🆘🆘什么数据都显示不出来,控制台也打印不出来,感觉是因为前后没连一起,但是不知道怎么改。
有没有人帮帮我。😭🙏😿🙏
用thymeleaf的th:each循环遍历不出来
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- okokabcd 2022-05-29 01:41关注
列一个能正确显示的操作,你可以对接看一下哪个环节出问题了
配置,application.yml# thymeleaf 静态资源配置 spring: thymeleaf: prefix: classpath:/templates/ encoding: UTF-8 suffix: .html mode: HTML5 # 关闭缓存, 即时刷新, 上线生产环境需要改为true cache: false servlet: content-type: text/html
后端
package com.example.thymeleaf.controller; import com.example.thymeleaf.entity.OrderItem; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.List; @Controller @RequestMapping("/demo") public class Demo01Controller { @RequestMapping("/cart") public String listOrders(Model model, HttpSession session) { System.out.println("demo/cart"); model.addAttribute("orders", getOrderItems()); return "mycart"; } private List<OrderItem> getOrderItems() { List<OrderItem> list = new ArrayList<>(); list.add(new OrderItem("1001", "订单1", "文件1")); list.add(new OrderItem("1002", "订单2", "文件2")); list.add(new OrderItem("1003", "订单3", "文件3")); return list; } }
前端
<table class="layui-table"> <thead> <tr> <th>序号</th> <th>订单号</th> <th>标题</th> <th>文件名</th> </tr> </thead> <tbody> <tr th:each="item:${orders}"> <td th:text="${itemStat.index+1}"></td> <td th:text="${item.orderId}"></td> <td th:text="${item.title}"></td> <td th:text="${item.fileName}"></td> </tr> </tbody> </table>
前台显示效果
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
- ¥20 matlab yalmip kkt 双层优化问题
- ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
- ¥88 实在没有想法,需要个思路
- ¥15 MATLAB报错输入参数太多