thymeleaf中使用layout功能,根据官方的文档,看上去非常的简单,但是就是各种搞不定。百度谷歌都没能查到有效的方案,有些方案是需要再写代码配置。

直到后来我在pom文件中更新的Thymeleaf的版本,才搞定。

原来我开发的时候,是从springboot官网http://projects.spring.io/spring-boot/#quick-start上下载了一个工程文件,这个工程文件里面的pom引用的版本竟然是旧的。

我也不知道为啥是这样,后来复写了一些版本号才搞定。真的坑死我了。下面是POM文件,主要看粗体字部分。

 

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.qmath

xlab

0.0.1-SNAPSHOT

jar

xlab

Demo project for Spring Boot

org.springframework.boot

spring-boot-starter-parent

1.5.6.RELEASE

UTF-8

UTF-8

1.8

3.0.2.RELEASE

2.0.4

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-data-jpa

mysql

mysql-connector-java

runtime

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-starter-thymeleaf

nz.net.ultraq.thymeleaf

thymeleaf-layout-dialect

org.springframework.boot

spring-boot-maven-plugin