SpringBoot(快速上手,运行静态html)

1 Thymeleaf入门

1.1 为什么要用 在进行我们web项目开发时,会有一个比较严重的问题,素材中提供给我们的是全部是html静态页 面,如果是我们以前开发,我们需要把这此些html页面转换成jsp页面。而转换之后的页面美工无法在 维护. 且页面添加了很多c标签,需要经过容器编译,SpringBoot项目首先是以jar包的方式存在而不是以 前的web项目,另外我们SpringBoot项目使用的是嵌入式的tomcat插件。 SpringBoot项目是默认不支持JSP,他有自己的前端框架,就是Thymeleaf。 1.2 添加依赖

<properties>
 <java.version>1.8</java.version> <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version> 
 <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout- dialect.version>
</properties> 

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

<dependency>
 <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
   <version>${
          
   thymeleaf.version}</version>
 </dependency> 


<dependency> 
<groupId>org.thymeleaf</groupId>
 <artifactId>thymeleaf-spring4</artifactId>
  <version>${
          
   thymeleaf.version}</version> 
  </dependency>

1.3 配置.yml 使用thymeleaf时只需要将文件存放到目录:“classpath:thmplates”,文件后缀为:”.html”可直接使 用 如需修改路径,请在application.properties 或ymal(略)中加入如下配置 #模板配置 spring: thymeleaf: prefix: classpath:templates/ suffix: .html mode: HTML5 encoding: UTF-8

经验分享 程序员 微信小程序 职场和发展