sringboot中使用thymeleaf动态模板刷新

  当springmvc转向springboot的时候,发现springboot默认支持thymeleaf,对于一直使用jsp的程序员,还是有点不适应。

不过研究了一会发现thymeleaf更加适合前后分离,所以果断抛弃jsp转入thymeleaf,最头疼的就是修改完之后不会自动刷新。

首先要在配置文件application.yml (或 application.properties)

spring
      thymeleaf:
        cache: false #重点是这个要设置false不然会无效
        prefix: classpath:/thymeleaf/
        suffix: .html
        mode: HTML5
        encoding: UTF-8

浏览器也需要设置disabled cache不然也不会有效果,图下图所示

保存后手动点击Build -> Build Project,也就是下图的按钮

这样thymeleaf就会自动更新页面数据。

希望以上对大家有帮助!

原文地址:https://www.cnblogs.com/zrl66/p/11423749.html