gpt4 book ai didi

java - Thymeleaf SpringEL 表达式

转载 作者:太空宇宙 更新时间:2023-11-04 10:02:21 25 4
gpt4 key购买 nike

我的 thymeleaf 模板有这样的问题。我得到:

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 是作为模型属性传递给 thymeleaf 模板的列表。我想知道为什么它不能正常工作。

我使用了这个来源: 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;
}
}

最佳答案

这个:

<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

关于java - Thymeleaf SpringEL 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53335986/

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