🆘🆘什么数据都显示不出来,控制台也打印不出来,感觉是因为前后没连一起,但是不知道怎么改。
有没有人帮帮我。😭🙏😿🙏
用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 WPF 大屏看板表格背景图片设置
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂
- ¥15 wordpress 产品图片 GIF 没法显示