1.spring-boot集成thymeleaf需要引入的依赖及版本
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> </parent> <!-- 修改jdk版本 --> <properties> <java.version>1.7</java.version> <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version> </properties> <dependencies> <!-- springBoot的启动器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies>注意:没有限制 thymeleaf和layout的版本会使得解析html模板文件的标签的闭合有限制。
org.xml.sax.SAXParseException: 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。
2.模板文件的路径与controller中返回字符串对应关系。
3.简单的模板写法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <span th:text="hello"></span> <br> <span th:text="${hello }"></span> </body> </html>
