最近在研究用 java 写网站,在使用 spring-boot-starter-thymeleaf 的 thymeleaf-layout-dialect 时老是无效,查阅了网站才知道,2.0之前的 spring-boot-starter-thymeleaf 自带 thymeleaf-layout-dialect 。2.0之后就没有自带了。那么怎么手动引入呢?
应该是
compile 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
而不是像 spring-boot-starter-thymeleaf 那样引入
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
最后附上完整的 build.gradle
plugins {
id 'org.springframework.boot' version '2.1.4.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'masterSpringMvc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
compile 'org.webjars:materializecss:1.0.0'
compile 'org.webjars:jquery:2.1.4'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}

本文介绍在Spring Boot 2.0及更高版本中,如何手动引入Thymeleaf Layout Dialect来增强Thymeleaf模板布局功能。由于2.0版本后Spring Boot不再默认包含此依赖,文章提供了正确的Gradle配置示例。

2624

被折叠的 条评论
为什么被折叠?



