SpringBoot使用thymeleaf模板引擎

(1)、添加pom依赖

  

1         <dependency>
2             <groupId>org.springframework.boot</groupId>
3             <artifactId>spring-boot-starter-thymeleaf</artifactId>
4         </dependency>

 

  *  SpringBoot1.x 默认的thymeleaf版本低,如果要自定义版本,需要在pom properties 覆写SpringBoot默认的thymeleaf版本号

  

1     <properties>
2         <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
3         <!--thymeleaf3需要布局功能layout2以上版本-->
4         <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>
5     </properties>

  

  *  SpringBoot2.x 无需此操作

 

(2)、将Html页面放至classpath:/templates/下,thymeleaf模板引擎将自动渲染

 

  *thymeleaf视图修改后,如何实时生效

  在配置文件中禁用thymeleaf缓存

spring.thymeleaf.cache=false

页面修改完成后Ctrl + F9重新编译(Idea)

浏览器刷新页面


*在控制器重定向跳转至静态资源目录而非thymeleaf目录,在配置类中注册一下转发映射

registry.addViewController("index/html").setViewName("index");

 

作者:奇

出处:https://www.cnblogs.com/fanqisoft/p/10323136.html

版权:本作品采用「本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。」许可协议进行许可。

posted @   SpringCore  阅读(1583)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示