javax.el.PropertyNotFoundException:类“java.lang.String”;没有财产
我正在创建示例 Spring MVC 应用程序。在我的 Controller 类中,我有这样的定义:
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
当我将以下部分放入 JSP 文件中时,我得到了 javax.el.PropertyNotFoundException 异常
<c:forEach items="${model.products}" var="prod">
<c:out value="${prod.description}"/> <i>$<c:out value="${prod.price}"/></i><br><br>
</c:forEach>
这是我的完整异常:
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'description'.
但是在我的域类中 private Sting description 属性具有公共 getter 和 setter。 Product
类是公共类。
产品类别:
public class Product implements Serializable {
private String description;
private Double price;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
}
PS:
如果我像这样使用它可以工作
<c:forEach items="${model.products}" var="prod" varStatus="status">
<c:out value="${model.products[status.count -1].description}"/> <i>$<c:out value="${model.products[status.count -1].price}"/></i><br><br>
</c:forEach>
但推荐的解决方案不起作用:(
I am creating Sample Spring MVC application. In my Controller class I have define like this:
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
When I put following part in my JSP file i got javax.el.PropertyNotFoundException
exception
<c:forEach items="${model.products}" var="prod">
<c:out value="${prod.description}"/> <i>lt;c:out value="${prod.price}"/></i><br><br>
</c:forEach>
Here is my full exception :
javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'description'.
But in my domain class private Sting description
property has public getter and setter. That Product
class is public one.
Product class:
public class Product implements Serializable {
private String description;
private Double price;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
}
PS:
If I used like this it's working
<c:forEach items="${model.products}" var="prod" varStatus="status">
<c:out value="${model.products[status.count -1].description}"/> <i>lt;c:out value="${model.products[status.count -1].price}"/></i><br><br>
</c:forEach>
But recommended solution not working :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您将字符串传递给 EL 操作 c:forEach 而不是可迭代元素时,会发生这种情况,在下面的示例中,我错过了“$”,因此它传递了精确的字符串,而没有变量解析。
下一个是正确的,因为操作在我的代码中是一个 String[]
This happen when you are passing a String to an EL operation c:forEach instead of an iterable element, in the following example I miss the '$' so it's passing the exact String without variable resolution.
The next is right because operation is a String[] in my code
也许检查您的 taglib 导入:
OLD
NEW
您的
Product
类及其 getter 是否可访问?我的意思是,它们是公开的
吗?请参阅http://forum.springsource.org/showthread。 php?58420-Problem-with-javax.el.PropertyNotFoundException。
Maybe check your taglib import:
OLD
NEW
Is your
Product
class and its getters accessible? By this I broadly mean are theypublic
?See http://forum.springsource.org/showthread.php?58420-Problem-with-javax.el.PropertyNotFoundException.
试试这个:
并检查 getter 和 setter 的大小写,应该是
getDescription()
Try this:
And check the capitalization of you gettters and setters, should be
getDescription()