SpringBoot整合Thymeleaf可能出现的问题及解决

昨天用SpringBoot整合Thymeleaf搞了好长时间,一直有问题,记录一下解决方案,希望帮助大家少走弯路。

1 模版依赖未导入

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2 一些配置信息

spring:
  thymeleaf:
    prefix: classpath:/templates/
    suffix: .html
    encoding: UTF-8
    mode: HTML5
    cache: false
    enabled: true

我的问题不在这里,但是很多解决方案都说修改这个可以成功
也有一些说设置成下面这样。
spring.thymeleaf.mode=LEGACYHTML5

3 SpringBoot对html的严格读

<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
    <version>1.9.22</version>
</dependency>

4 版本问题

这个版本不兼容问题是解答里说的最多的。
需要在pom文件里的properties标签指定版本

    <properties>
        <java.version>1.8</java.version>
        <thymeleaf-spring5.version>3.0.9.RELEASE</thymeleaf-spring5.version>
        <thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
    </properties>

复现了一下,当时以为是版本问题

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [login], template might not exist or might not be accessible by any of the configured Template Resolvers
	at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE

5 打包问题

我的问题就是这个,我因为先整合的mybatis的依赖,
加入了如下

          <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                </includes>
            </resource>

把这段删了或者加上

            <resource>
                <directory>src/main/resources</directory>
            </resource>

即可,
我最终是这个问题。

写在最后

写的时候一直提示获取不到资源,应该往这方面想。
在这里插入图片描述
希望对大家有用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值