Val*_*jon 3 java spring thymeleaf spring-boot
将 Spring-Boot 从 迁移1.5.3.RELEASE到 后2.2.2.RELEASE,Thymeleaf 停止工作。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我已经按照Thymeleaf 3 迁移指南+ 阅读Spring-Boot 版本,但没有成功......
layout:decorate)<!DOCTYPE html>
<html th:lang="${#locale}" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
xmlns:layout="https://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="layout">
<head>
<title></title>
</head>
<body>
<div layout:fragment="content">
Run Code Online (Sandbox Code Playgroud)
http://localhost/index 路径比较:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>APLLICATION</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'/><![endif]-->
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<meta name="description" content="Application description" />
<meta name="fragment" content="text" />
<link rel="stylesheet" href="css/vendor/bootstrap.min.css" />
<link rel="stylesheet" href="css/vendor/jquery-ui.min.css" />
...
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="https://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="layout">
<head>
<title></title>
</head>
<body>
<div layout:fragment="content">
...
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。谢谢
编辑:
@Marged,模型设置:
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index");
...
}
}
Run Code Online (Sandbox Code Playgroud)
上下文路径默认为 ( /)
@SpringBootApplication(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
@EnableConfigurationProperties({ AppConfig.class })
@EnableScheduling
@EnableJpaRepositories
@EnableAutoConfiguration
@ComponentScan("foo.bar")
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
您的问题似乎与Thymeleaf 布局方言有关(请参阅 #4)。Spring-Boot1.5.3.RELEASE支持开箱即用,但2.2.2.RELEASE不支持。这甚至在方言的文档中有所说明:
布局方言已作为 Spring Boot 1.x 中 Thymeleaf 入门包的一部分包含在内,但已在 Spring Boot 2 中删除,因此上述 Spring Boot 2 用户的额外配置步骤。
上面链接中的以下安装步骤应该会有所帮助,即:
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.4.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
@Bean到您的配置中:@Bean
public LayoutDialect layoutDialect() {
return new LayoutDialect();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |