当前位置: 首页 > 知识库问答 >
问题:

升级到Spring Boot 2.2.2。释放胸腺叶3.0.11。释放,thymeleaf/布局停止工作

宋高扬
2023-03-14

在从1.5.3迁移Spring-Boot之后。RELEASEto2.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>

我已经按照Thymeleaf3迁移指南阅读了Spring Boot发行版,但没有成功。。。

<!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">

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" />
    ...
<!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">
...

谢谢你的帮助。谢谢

编辑:

@标记,模型设置:

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index");
        ...
    }

}

默认情况下为上下文路径(/

@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);
    }
}

共有1个答案

太叔超英
2023-03-14

您的问题似乎与Thymeleaf Layout方言有关(见#4)。Spring-引导1.5.3。RELEASE支持开箱即用,但2.2.2。RELEASE没有。这是甚至表示在方言的留档:

在Spring Boot 1. x中,布局方言已经作为Thymeleaf启动器包的一部分包含在内,但在Spring Boot 2中已经删除,因此上面的Spring Boot 2用户需要额外的配置步骤。

下面的安装步骤从上面的链接应该是有帮助的,例如:

  • 添加maven依赖:
<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>2.4.1</version>
</dependency>
  • 向您的配置中添加额外的@Bean
@Bean
public LayoutDialect layoutDialect() {
    return new LayoutDialect();
}
 类似资料:
  • 我想做一些像 在百里香叶中。我知道有一个价值观,我要做的就是 如何在Thyemleaf的select选项中传递两个值。

  • 我正在将Exoplayer与ViewPager2配合使用。 主片段。Java语言 fragment_home.xml ViewpagerAdapter。Java语言 customviewPager。xml 我想在滑动页面时释放并停止播放器。只有当前正在查看的页面才应该运行exoplayer。运行所有播放器会导致性能问题。我尝试使用onViewDetachedFromWindow方法释放播放器,但如

  • 我试图在thymleaf中迭代函数列表。这就是我所做的。 控制器: 并在html中: 我是新来的。我做错了什么?或者我应该使用?

  • 我想把JavaScript onClick属性使用Thym立叶。 我这样写代码 此代码正在运行。当productName包含这样的特殊字符时,我会遇到问题 然后JavaScript函数看起来像这样 我需要从产品名称中转义双引号和单引号字符。我该怎么做?

  • 以前的版本: springCloudVersion="格林威治。RELEASE"springBootVersion="2.1.13.发布” 升级版本: springCloudVersion="Hoxton.SR3"springBootVersion="2.3.11.发布” Spring代码: 升级后出错: 我尝试过的事情: 尝试使用后映射而不是请求映射。 使用了不同的媒体类型,但都不起作用。 任何

  • 当图像存在时,我想在thymleaf中显示背景图像,但如果不存在,我想在那里显示默认图像。我试过的如下 在最后一个空引用中,我想放一个这样的默认图像 但它显示出错误。正确的语法是什么?