Thymeleaf注意事项

导航栏作为公共页面

1. 公共部分提取

 //提取Html头,以及css,js且让title动态显示
        title
//提取不需要变化的公共部分

2. 公共页面引入

  //引入Html头后,传入当前页面title
 
//引入公共不需要变化的部分
   //引入导航栏,并进行传入key值,为后续高亮处理做铺垫

3.Thymeleaf的三个不同引入方法的区别

属性 特点
th:replace 不保留自己的主标签,保留th:fragment的主标签
th:include 保留自己的主标签,不保留th:fragment的主标签
th:insert 保留自己的主标签,也保留th:fragment的主标签

导航栏在对应页面高亮处理

  • 项目模块管理
  • Thymeleaf注意点

    1. 配置非严格的语法,thymeleaf 有严格的语法限制,会极大程度限制你的发挥,所以先把这个模板的严格去掉

    
    
              net.sourceforge.nekohtml
              nekohtml
              1.9.22
          
    

    2.在application.properties中配置(可选)

    
    spring.thymeleaf.cache=false
    ## 检查模板是否存在,然后再呈现
    spring.thymeleaf.check-template-location=true
    #Content-Type值
    spring.thymeleaf.content-type=text/html
    #启用MVC Thymeleaf视图分辨率
    spring.thymeleaf.enabled=true
    ## 应该从解决方案中排除的视图名称的逗号分隔列表
    ##spring.thymeleaf.excluded-view-names=
    #模板编码
    spring.thymeleaf.mode=LEGACYHTML5
    # 在构建URL时预先查看名称的前缀
    spring.thymeleaf.prefix=classpath:/templates/
    # 构建URL时附加查看名称的后缀.
    spring.thymeleaf.suffix=.html
    

    3.Thymeleaf书写

    
    
    
    html:
    JS: var urls = [[${address}]] ;
    
    
    
    
    

    4.Select数据回显选中

    
    
    

    5. Thymeleaf在js中从modle取值

    totalPages:[[${pageInfo.pages}]],   //总页数
    

    6.遇到的一个问题

    
    
    
    
    
    

    你可能感兴趣的:(Thymeleaf注意事项)