因为在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有作详细的介绍和记录,致使有些朋友用起来有些吃力,所以打算在接下来的时间里作一些基础整合的介绍,固然,可能也不会特别的基础,可是源码会开放给你们,方便你们学习,这次的源码地址为springboot-thymeleaf,多谢你们支持。html
Thymeleaf是一个跟Velocity、FreeMarker相似的模板引擎,它能够彻底替代JSP,相较与其余的模板引擎,它有以下三个极吸引人的特色:java
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>com.my.blog</artifactId> <name>springboot-thymeleaf</name> <description>springboot-thymeleaf</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <properties> <java.version>1.7</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
# thymeleaf spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.check-template-location=true spring.thymeleaf.suffix=.html spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html spring.thymeleaf.mode=HTML5 spring.thymeleaf.cache=false
在resources文件夹下新增templates目录,用于存放模板文件,新增hello.html。git
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"/> <title>springboot-thymeleaf demo</title> </head> <body> <p th:text="'hello, ' + ${name} + '!'" /> </body> </html>
HelloController :程序员
/** * author:13 * date:2017-09-14 */ @Controller public class HelloController { @RequestMapping("/hello") public String hello(HttpServletRequest request, @RequestParam(value = "name", required = false, defaultValue = "springboot-thymeleaf") String name) { request.setAttribute("name", name); return "hello"; } }
WebApplication :github
/** * author:13 * date:2017-09-14 */ @SpringBootApplication public class WebApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(WebApplication.class); } public static void main(String[] args) throws Exception { SpringApplication.run(WebApplication.class, args); } }
项目启动后,在浏览器端输入如下urlhttp://localhost:8080/hello
:
spring
首发于个人我的博客。apache
若是有问题或者有一些好的创意,欢迎给我留言,也感谢向我指出项目中存在问题的朋友。浏览器
代码和此次的问题都是My Blog项目中的,若是你想继续了解该项目能够查看整个系列文章Java开源博客My-Blog(SpringBoot+Docker)系列文章,也能够到个人GitHub仓库或者开源中国代码仓库中查看源码及详细的部署过程和使用文档。springboot