我的百里香模板有这样的问题。我得到了:
Exception evaluating SpringEL expression: "prod.itemName" (main:18)
从此表达式:
<tr th:each="prod: ${product}">
<td th:text="${prod.itemName}">sdfsdf</td>
<td th:text="${prod.price}">asdasd</td>
<td>asddasdas</td>
</tr>
product是作为模型属性传递到百里香模板的列表。我想知道为什么它不能正常工作。
我使用了这个来源: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#iteration-basics
已编辑:
package shopbasket;
public class Item {
String itemName;
double price;
Item(String itemName, double price){
this.itemName=itemName;
this.price=price;
}
void setItemName(String itemName) {
this.itemName=itemName;
}
String getItemName() {
return itemName;
}
void setPrice(float price) {
this.price=price;
}
double getPrice() {
return price;
}
}
答案 0 :(得分:0)
这个:
<tr th:each="prod : ${prods}">
<td th:text="${prod}">sdfsdf</td>
<td th:text="${prod}">asdasd</td>
<td>asddasdas</td>
</tr>
给出输出:
shopbasket.Item@10d9f966 shopbasket.Item@10d9f966 asddasdas
shopbasket.Item@1346081f shopbasket.Item@1346081f asddasdas
shopbasket.Item@4c8bc1d8 shopbasket.Item@4c8bc1d8 asddasdas
shopbasket.Item@7b0d2332 shopbasket.Item@7b0d2332 asddasdas
shopbasket.Item@6e38515f shopbasket.Item@6e38515f asddasdas
shopbasket.Item@4d9daa77 shopbasket.Item@4d9daa77 asddasdas
shopbasket.Item@5f0a371d shopbasket.Item@5f0a371d asddasdas
shopbasket.Item@4d0c8b7d shopbasket.Item@4d0c8b7d asddasdas
shopbasket.Item@6112892a shopbasket.Item@6112892a asddasdas
shopbasket.Item@41fc596d shopbasket.Item@41fc596d asddasdas
shopbasket.Item@4fc03c90 shopbasket.Item@4fc03c90 asddasdas
shopbasket.Item@663e1176 shopbasket.Item@663e1176 asddasdas
shopbasket.Item@13909f42 shopbasket.Item@13909f42 asddasdas
答案 1 :(得分:0)
改为尝试使用此表单:<td th:inline="text">[[${prod.price}]]</td>