【发布时间】:2019-12-26 00:13:56
【问题描述】:
我有一个 MenuItems 域和一个包含所有 MenuItems 列表的 Menu 容器,我试图将 arraylist 从 spring 控制器传递到前端。
这是 MenuItems 域:
public class MenuItems {
private String itemName;
private String itemDescription;
private String itemPrice;
private String itemQuantity;
private String itemCategory;
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemDescription() {
return itemDescription;
}
public void setItemDescription(String itemDescription) {
this.itemDescription = itemDescription;
}
public String getItemPrice() {
return itemPrice;
}
public void setItemPrice(String itemPrice) {
this.itemPrice = itemPrice;
}
public String getItemQuantity() {
return itemQuantity;
}
public void setItemQuantity(String itemQuantity) {
this.itemQuantity = itemQuantity;
}
public String getItemCategory() {
return itemCategory;
}
public void setItemCategory(String itemCategory) {
this.itemCategory = itemCategory;
}
}
这是菜单容器:
public class MenuContainer {
private List<MenuItems> menuAList;
public List<MenuItems> getMenuItems() {
return menuAList;
}
public void setMenuItems(List<MenuItems> menuList) {
menuAList = menuList;
}
public String toString(){
return menuAList.toString();
}
}
这是控制器:
@RequestMapping(value = "/admin/home", method = RequestMethod.GET)
public String home(Model model) throws Exception{
List<MenuItems> menuItems = KafkaConsumerFromTopic.menuArrayL;
MenuContainer menuL = new MenuContainer();
menuL.setMenuItems(menuItems);
model.addAttribute("menuItems", menuL);
//System.out.println(menuL.toString());
return "/admin/home";
}
这是我在百里香模板中的内容:
<table>
<thead>
<tr>
<th>Item Name</th>
<th>Item Description</th>
<th>Item Price</th>
<th>Item Quantity</th>
<th>Item Category</th>
</tr>
</thead>
<tbody>
<tr th:each="menuItem : ${menuItems}">
<td th:text="${menuItem.itemName}"></td>
<td th:text="${menuItem.itemDescription}"></td>
<td th:text="${menuItem.itemPrice}"></td>
<td th:text="${menuItem.itemQuantity}"></td>
<td th:text="${menuItem.itemCategory}"></td>
</tr>
</tbody>
</table>
这是我收到的错误消息:
org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-10] 异常处理模板“/admin/home”:异常评估 SpringEL 表达式:“menuItem.itemName”(模板:“/admin/家” - 第 23 行,第 25 列)
【问题讨论】: