1. 概述

  1. spring 配合 thymeleaf 关闭页面缓存

2. 背景

  1. 最近复习 spring

  2. 找了本书叫 spring in action 5th

    1. 本人水平有限
    2. 书还写得那么难
  3. 调试中遇到了问题

    1. 问题1: 我每次改代码, 都要重启
    2. 问题2: 我每次改页面, 都要重启
  4. 因为 问题2 对我来说, 优先级最高, 我首先解决它

3. 环境

  1. os

    1. win10
  2. jdk

    1. 1.8
  3. ide

    1. ida 2018.1
  4. spring

    1. spring boot

      1. 2.1.7 release
    2. 组件
      1. thymeleaf
      2. starter-web
      3. devtool
      4. starter-test
  5. browser

    1. firefox

      1. 70.0
  6. ref

    1. spring in action 5th

4. 问题

  1. 期望

    1. 在 ide 修改页面
    2. 在浏览器直接刷新, 就能看到页面调整
  2. 需要保证

    1. 浏览器的正确配置

      1. 浏览器

        1. 确保每次请求, 都是新鲜的页面
    2. spring 和 thymeleaf 的正确配置
      1. spring

        1. 确保 thymeleaf 的修改能及时

5. 问题解决

  1. 浏览器

    1. 思路1: 每次访问后清空缓存

      1. 结果

        1. 否决

          1. 太麻烦了
    2. 思路2: 通过浏览器配置, 确保每次请求, 都是新页面

      1. 结果

        1. 这个方案不错
        2. 而且也有配置项可以做到
        3. 因为很顺利, 就不细说了, 照着配置一步步来就行
      2. ref

        1. 设置火狐浏览器不缓存js与html
  2. thymeleaf

    1. 思路: 找到配置项, 配置一下就好了

      1. 结果

        1. 妈的找死我了
        2. 百度了好多, 都没用
          1. 千篇一律, 只有一条参数

            spring.thymeleaf.cache=false
          2. 结果配置了根本不生效

          3. 这感觉太难受了, 真的想骂人

      2. 最后结果

        1. ref

          1. Thymeleaf templates cache even when spring.template.cache: false

            1. 一个叫 oak1980 的丹麦老哥, 给了一个配置如下

              # Templates reloading during development
              spring.thymeleaf.prefix=file:src/main/resources/templates/
              spring.thymeleaf.cache=false # Static resources reloading during development
              spring.resources.static-locations=file:src/main/resources/static/
              spring.resources.cache-period=0
          2. 按照这个老哥的做法, 配置终于生效

ps

  1. 妈的为啥我百度的头几个, 没有一个把事说明白

    1. 大部分只给了 cache = false 的那条配置
    2. 其他提到 prefix 的, 还都把 prefix 注释了
    3. 配置的 ide, 组件, 版本也没有
    4. 找了好半天, 问题是这种都是调试常识之类的东西
  2. spring 如何确认运行阶段生效了哪些配置项

    1. 这个找了半天, 也没找到
    2. 我总觉得可以...

Spring - MVC - thymeleaf 缓存关闭的更多相关文章

  1. Spring MVC + Thymeleaf

    参考网址: https://www.cnblogs.com/litblank/p/7988689.html 一.简介 1.Thymeleaf 在有网络和无网络的环境下皆可运行,而且完全不需启动WEB应 ...

  2. 使用maven简单搭建Spring mvc + redis缓存

    注:此文参考并整合了网上的文章 <spring缓存机制>:http://blog.csdn.net/sidongxue2/article/details/30516141 <配置 S ...

  3. 使用方法拦截机制在不修改原逻辑基础上为 spring MVC 工程添加 Redis 缓存

    首先,相关文件:链接: https://pan.baidu.com/s/1H-D2M4RfXWnKzNLmsbqiQQ 密码: 5dzk 文件说明: redis-2.4.5-win32-win64.z ...

  4. A real ROCA using Bootstrap, jQuery, Thymeleaf, Spring HATEOAS and Spring MVC

    http://www.tuicool.com/articles/ENfe2u https://github.com/tobiasflohre/movie-database What is the be ...

  5. Spring MVC视图层:thymeleaf vs. JSP

    本文对比了同一Spring MVC工程中相同页面(一个订阅表单)分别采用Thymeleaf和JSP(包括JSP.JSTL.Spring tag lib)两种方式的实现. 本文的所有代码来自一个可运行的 ...

  6. Thymeleaf 3与Spring MVC 4 整合配置

    Thymeleaf 3与Spring MVC 4 整合配置 Maven 依赖配置 Spring 相关依赖就不说了 <dependency> <groupId>org.thyme ...

  7. Spring MVC 5 + Thymeleaf 基于Java配置和注解配置

    Spring MVC 5 + Thymeleaf 注解配置 Spring的配置方式一般为两种:XML配置和注解配置 Spring从3.0开始以后,推荐使用注解配置,这两种配置的优缺点说的人很多,我就不 ...

  8. 在Spring MVC和Spring Boot中使用thymeleaf模板

    Spring MVC: POM: <!-- thymeleaf模板 --> <!-- https://mvnrepository.com/artifact/org.thymeleaf ...

  9. Spring MVC : Java模板引擎 Thymeleaf (二)

    本文原计划直接介绍Thymeleaf的视图解析,但考虑到学习的方便,决定先构建一个spring-mvc. 以下的全部过程仅仅要一个记事本和JDK就够了. 第一步,使用maven构建一个web app. ...

随机推荐

  1. centos7搭建天兔

    如果新系统尚未安装工具pip,可通过以下三步快速安装pip              1.  yum -y install epel-release               2.  yum -y ...

  2. Selenium3+python自动化009-iframe定位

    iframe 一.frame:HTML页面中的一种框架,主要作用是在当前页面中指定区域显示另一页面元素: 二.操作Frame中的页面元素 定位元素: 1.id定位driver.switch_to.fr ...

  3. 自定义Ribbon客户端策略

    说明   为了实现Ribbon细粒度的划分,让调用不同的微服务时采用不同的客户端负载均衡策略, 通常情况下我们会自定义配置策略.   本文以内容中心(content-center)调用户中心微服务(u ...

  4. eclipse下载更新可用的SDK 2018-11-12

    懒人方法: mirrors.neusoft.edu.cn:80 操作步骤: 1. Android SDK Manager----Tools----Options-----Http Proxy Serv ...

  5. 线段树的树状数组大小为什么是4*maxn

    以下方建树代码为例,r数组表述原始数据,t表述tree也就是树状数组 void make(int left,int right,int num)//创建线段树 { t[num].l=left; t[n ...

  6. pl/sql developer试用期结束

    (产品代码)Product Code:ljkfuhjpccxt8xq2re37n97595ldmv9kch (序列号)Serial Number:302967 (口令)Password:xs374ca ...

  7. Exception in thread "http-apr-8080-exec-1" java.lang.StackOverflowError

    Exception in thread "http-apr-8080-exec-1" java.lang.StackOverflowError 可能执行了递归,陷入了死循环 如下我 ...

  8. 杭电oj 2072————统计单词数(java)

    problem:统计单词数 思路:利用HashMap的特性——不能反复存储同一个键得数据,所以可以保证map里边儿的元素都是不重复的,存储完毕之后直接输出size就好了 注意事项: 1.利用strin ...

  9. 小匠第二周期打卡笔记-Task04

    一.机器翻译及相关技术 机器翻译(MT):将一段文本从一种语言自动翻译为另一种语言,用神经网络解决这个问题通常称为神经网络翻译(NMT). 主要特征:输出是单词序列而不是单个单词.输出序列的长度可能与 ...

  10. oracle数据库操作 接口封装

    1.如下 using Oracle.ManagedDataAccess.Client; using System; using System.Collections.Generic; using Sy ...