thymeleaf双重循环_spring boot: 用thymeleaf嵌套循环展示多层数据(spring boot 2.3.2)

本文详细介绍了如何在Spring Boot项目中利用Thymeleaf进行双重循环来展示多个分类及其每个分类下的推荐商品。通过创建Category和Goods模型类,设置相关属性,并在HomeController中模拟数据,最终在category.html模板中展示。项目源码可在GitHub找到。
摘要由CSDN通过智能技术生成

一,什么情况下会用到嵌套循环?

当我们展示多个分类时,每个分类下又展示出推荐的前几个商品,

这时我们需要用到嵌套循环

看一个例子:

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,演示项目的相关信息

1,项目地址:

https://github.com/liuhongdi/templateloop

2,项目功能说明:

演示了模板中常用的嵌套循环

3,项目结构;如图:

三,配置文件说明

1,pom.xml

org.springframework.boot

spring-boot-starter-thymeleaf

2,application.properties

#errorserver.error.include-stacktrace=always#errorlogging.level.org.springframework.web=trace

#thymeleaf

spring.thymeleaf.cache=falsespring.thymeleaf.encoding=UTF-8spring.thymeleaf.mode=HTML

spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.html

四,java程序说明

<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值