thymeleaf的简单记录
thymeleaf的简单记录
1:springboot项目的thymeleaf资源放置于resource/templates下
application.properties中需要增加下面的配置
1 2 3 4 5 | #html的thymeleaf静态资源的导入以及配置 spring.thymeleaf.suffix=.html spring.thymeleaf.encoding=UTF- 8 spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.enabled= true |
2:定义html的thymeleaf模板需要引入thymeleaf的命名空间
1 | <html lang= "en" xmlns:th= "http://www.thymeleaf.org" > |
3:相关语法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 1:单变量传递th:text =${变量} 使用该标签接受变量取值 1举例: 后台: model.addAttribute("msg",要传递的内容); 前台: < div th:text="${msg}"></ div >2:循环体传递 th:each= "单体名:${循环体}" th:text="${单体名}" 2:举例: 后台: model.addAttribute("users", Arrays.asList("mike","jetty","mary")); 前台: < h3 th:each="user:${users}" th:text="${user}"></ h3 > |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律