gpt4 book ai didi

spring - javax.el.PropertyNotFoundException : The class 'java.lang.String' does not have the property

转载 作者:行者123 更新时间:2023-12-02 06:58:30 25 4
gpt4 key购买 nike

我正在创建示例 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>

这是我的完整异常(exception):

javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'description'.

但是在我的域类中 private Sting description 属性具有公共(public) getter 和 setter。 Product 类是公共(public)类。

产品类别:

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>

但是推荐的解决方案不起作用:(

最佳答案

当您将字符串传递给 EL 操作 c:forEach 而不是可迭代元素时,会发生这种情况,在下面的示例中,我错过了“$”,因此它传递了精确的字符串,而没有变量解析。

<c:forEach var="o" items="{operations}">

下一个是正确的,因为我的代码中的操作是 String[]

<c:forEach var="o" items="${operations}">

关于spring - javax.el.PropertyNotFoundException : The class 'java.lang.String' does not have the property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7318004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com