Spring thymeleaf

1.maven项目引入thymeleaf包

在pom.xml文件中,添加依赖

    <!-- 依赖库 -->
    <dependencies>
        <!-- Springboot核心 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <!-- logging -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <!-- mybatis + mysql -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>
        <dependency><!-- 分页插件 -->
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.10</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        
        <!-- AOP -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        
        <!--start thymeleaf -->
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-thymeleaf</artifactId>  
        </dependency>
        
        <!--Quartz
        Spring 项目整合 Quartz 主要依靠添加 SchedulerFactoryBean 这个 FactoryBean,
         所以在maven 依赖中添加 spring-context-support 。-->
        <dependency>
          <groupId>org.quartz-scheduler</groupId>
          <artifactId>quartz</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
        </dependency>
        
        <!-- security-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>
        
        <!-- 支持 @ConfigurationProperties 注解 -->  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-configuration-processor</artifactId>  
            <optional>true</optional>  
        </dependency>  

        <!-- java mail -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!-- 支持 Excel操作 -->  
        <dependency>  
            <groupId>org.apache.poi</groupId>  
            <artifactId>poi-ooxml</artifactId>  
            <version>3.9</version>  
        </dependency>
    </dependencies>

 

2..application.yml中添加:

    thymeleaf: #thymeleaf
        prefix: classpath:/templates/
        suffix: .html
        mode: HTML
        encoding: UTF-8
        cache: true #turn off when in developing or cant refresh immdiately
        servlet:
            content-type: text/html

 

3.在HTML中添加:

<html xmlns:th="http://www.thymeleaf.org"
    xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

 

posted on 2019-07-12 11:48  青柠锦鲤  阅读(173)  评论(0编辑  收藏  举报