Thymeleaf模版引擎代替jsp

1. pom


			org.springframework.boot
			spring-boot-starter-thymeleaf
		
		
			net.sourceforge.nekohtml
			nekohtml
			1.9.22
		

2. application.properties

#配置thymeleaf格式要求
spring.thymeleaf.mode = LEGACYHTML5
spring.thymeleaf.prefix=classpath:/templates/html/     #不要漏写html后面的斜杠
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
#声明thymeleaf使用非严格的html。
spring.thymeleaf.content-type=text/html
##默认情况下,页面会被浏览器缓存,开发阶段设置为false
spring.thymeleaf.cache=false

 Thymeleaf默认的视图解析:

Thymeleaf模版引擎代替jsp_第1张图片

3. 页面

在头html中 引入lang="en" xmlns:th="http://www.thymeleaf.org"即可



        
        登录
        


	

   后台

Thymeleaf模版引擎代替jsp_第2张图片

 

4. 在页面中访问静态资源

静态资源存放目录

Thymeleaf模版引擎代替jsp_第3张图片

 

页面中这么引入静态文件

1

2

3

<img src=”/images/….”>

<script src=”/js/….”>

<link href=”/css/….”>

注意:无需带上static目录哦。

你可能感兴趣的:(java,前端,springboot)