今天在做SpringBoot项目开发的时候,因为很久都没用过thymeleaf模板了,现在大部分项目都是前后端分离项目,前端使用VUE等框架,很少使用到后端的thymeleaf模板引擎。使用过程中遇到了通过Controller 找到视图页面后图片找不到问题。

  1. 先是在百度上,百度了一下网友的解决办法,包括配置yml等,但是都没用什么作用。我的thymeleaf yml配置如下:

spring:
thymeleaf:
cache: false
encoding: UTF-8
mode: HTML5
prefix: classpath:/templates/
enabled: true
suffix: .html
content-type: text/html
check-template: true
check-template-location: true

  1. 报错信息如下:
    在这里插入图片描述
  2. 解决办法:
    1.首先确保你的图片的URL引用地址是正确的。
    2.确保你的配置中没有拦截静态资源和图片
    3 .检查target文件,去静态资源文件夹下边查看是否将静态资源文件编译到target对应文件夹下。如果没有,配置pom.xml
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.yml</include>
                <include>**/*.properties</include>
                <include>**/*.ico</include>
                <include>**/*.sql</include>
                <include>**/*.css</include>
                <include>**/*.jpg</include>
                <include>**/*.png</include>
                <include>**/*.js</include>
                <include>**/*.html</include>
            </includes>
            <filtering>true</filtering>
        </resource>
Logo

前往低代码交流专区

更多推荐