springBoot thymeleaf与Spring整合

thymeleaf在javaweb中运用的越来越多了,最主要的原因可能在于,jsp在运用中不能很好的将前后端分离,而thymeleaf是以.html为后缀,能够不需要启动整个应用,直接的在浏览器中进行浏览,下面我们就看看如何将thymeleaf与spring进行整合:

1.引入依赖

maven中直接引入

  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-thymeleaf</artifactId>
   </dependency>

2.配置视图解析器

spring-boot很多配置都有默认配置,比如默认页面映射路径为
classpath:/templates/*.html
同样静态文件路径为
classpath:/static/

在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC的JSP解析器配置一样

#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
#thymeleaf end

3.编写代码

4.基础语法

链接:http://blog.csdn.net/dengchenrong/article/details/78192499

猜你喜欢

转载自blog.csdn.net/dengchenrong/article/details/78192686