zoukankan      html  css  js  c++  java
  • spring boot2.3.0集成 thymelaf

     

    1. 配置pom

      1. 如果是2.x的直接配置一个starter即可

          <!-- ThymeLeaf 依赖 -->
        <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

         

      2. 如果是1.x的 还需要配置一些参数

          <!-- 布局功能的支持程序  thymeleaf3主程序  layout2以上版本 -->
        <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>

         

    2. resoruces下面建立 templates文件夹

    3. 把html文件放在templates里面,以.html结尾,可以在html里面加入命名声明

      1. <html lang="en" xmlns:th="http://www.thymeleaf.org">

         

    4. 编写controller类,用@Controller 不要用@RestController!如果前后端分离不是很彻底的项目,建议在controllr包 分为API和view包。分别放纯接口返回一个放模板访问的

      @Controller //注意  不要用 RestController
      public class Say {
          @RequestMapping("hi") 
          public String hi() {
              return "/list"; //需要加入”/“, 反而RequestMapping里面如果是直接访问反而不需要"/”
          }
      }
      

        

    5. 配置application.yml文件(非强制)
      spring:
          thymeleaf:
              mode: HTML
              encoding: UTF-8
              servlet:
                  content-type: text/html
              prefix: classpath:/templates
              suffix: .html
              cache: false
      

        

       

       

       

  • 相关阅读:
    C#生成PDF总结
    Oracle删除当前用户下所有的表的方法
    C#操作oracle 到ExecuteNonQuery卡死不执行
    C#中事件的使用
    初探three.js光源
    d3.js 地铁轨道交通项目实战
    初探three.js
    d3.js 绘制北京市地铁线路状况图(部分)
    d3.js 共享交换平台demo
    d3.js 实现烟花鲜果
  • 原文地址:https://www.cnblogs.com/jinbiao/p/13048308.html
Copyright © 2011-2022 走看看