在 Spring Boot 中设置 Thymeleaf 的缓存策略,你需要在 application.properties 或者 application.yml 文件中添加相应的配置
application.properties 文件:# 关闭 Thymeleaf 模板缓存spring.thymeleaf.cache=false# 设置模板前缀和后缀spring.thymeleaf.prefix=classpath:/templates/spring.thymeleaf.suffix=.html# 设置模板编码spring.thymeleaf.encoding=UTF-8使用 application.yml 文件:spring: thymeleaf: cache: false # 关闭 Thymeleaf 模板缓存 prefix: classpath:/templates/ # 设置模板前缀 suffix: .html # 设置模板后缀 encoding: UTF-8 # 设置模板编码通过将 spring.thymeleaf.cache 属性设置为 false,你可以关闭 Thymeleaf 的模板缓存。这样,每次请求时都会重新加载模板,有助于开发过程中实时查看修改后的页面效果。在生产环境中,建议开启缓存以提高性能。


