Spring Boot thymeleaf 模板使用(二)
本文介绍Spring Boot thymeleaf 基础使用,thymeleaf模板引擎是Spring Boot推荐使用的引擎。
- Thymeleaf 介绍
 
Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎。类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用的模板引擎。与其它模板引擎相比,Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个Web应用。
快速开始
本文介绍快速搭建一个demo,并提供简单的服务。
源码下载:https://github.com/fallsea/springboot/tree/master/spring-boot-1
环境依赖
jdk1.7Spring Boot 1.5.8.RELEASE
使用maven构建项目
可以使用spring提供的地址,快速构建一个基础环境
快速构建地址:https://start.spring.io/
构建成功后,解压压缩包,导入eclipse环境。
项目结构分析
SpringBoot1Application,Spring Boot服务启动类application.properties,Spring Boot配置文件SpringBoot1ApplicationTests,测试类
开发一个demo
- pom引入 
spring-boot-starter-web模块 
1  | <dependency>  | 
- 新建一个 
com.fallsea.springboot1.controller包路径 - 新建java类 
DemoController.java,内容如下: 
1  | 
  | 
- 启动服务,执行 
SpringBoot1Application类 
- 浏览器打开 
http://localhost:8080/hello查看访问结果 
pom引用分析
spring-boot-starter核心模块,包括自动配置支持、日志等spring-boot-starter-test测试模块,包括JUnit等spring-boot-starter-webweb模块


