我正在尝试遍历 List 并在表格中显示结果,但表格仍为空。控制器@RequestMapping(value="/home") public String home(Model model) throws IOException { List<OrderNotify> notifications = new ArrayList<OrderNotify>(); for (int i = 0; i < 10; i++) { OrderNotify notification = new OrderNotify("1", "2", "3", "4"); notifications.add(notification); } model.addAttribute("notifications", notifications); return "home"; }home.jsp - 表格<table id="handle" style=" margin:auto"> <tr> <th>Bestellnummer</th> <th>Datum</th> <th>Status</th> <th>Handlung erforderlich</th> </tr> <tr th:each="notify : ${notifications}"> <td th:text="${notify.orderid}"></td> <td th:text="${notify.date}"></td> <td th:text="${notify.status}"></td> <td th:text="${notify.handle}"> </td> </tr></table>OrderNotify.javapublic class OrderNotify { public String orderid; public String date; public String status; public String handle; public OrderNotify(String orderid, String date, String status, String handle) { this.orderid = orderid; this.date = date; this.status = status; this.handle = handle; } public List<String> getAll(){ return null; } public String getOrderid() { return orderid; } public void setOrderid(String orderid) { this.orderid = orderid; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getHandle() { return handle; } public void setHandle(String handle) { this.handle = handle; }}
1 回答
跃然一笑
TA贡献1826条经验 获得超6个赞
Thymeleaf 和 JSP 是两种不同的服务器端渲染模板。没有配置你不能同时使用它们。
根据您的代码,您应该更新使用 Thymeleaf 的设置
:将 home.jsp 更改为 home.html
b. 将 home.html 移动到路径:src/main/resources/templates
c。在 application.properties 中配置 Thymeleaf:
# Thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
d. 在 pom.xml 中配置 Thymeleaf 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
对于Viewing templates,SpringBoot推荐使用Thymeleaf而不是JSP
在SpringBoot应用中同时使用Thymeleaf和JSP,还需要配置更多。
添加回答
举报
0/150
提交
取消