如何在百里香叶(春季启动项目)中加载核心图像?

问题描述 投票:0回答:1

我想在我的Spring Boot应用程序中发生错误后显示图像。我阅读了文档并尝试了几种方法,但仍然无法使用。

我阅读了文档,并尝试了几种方法,但仍然无法使用。我尝试这个:

<img th:src="@{/images/error_image.jpg}"/>

和此:

<img src="../static/images/error_image.jpg" th:width="1000" th:src="@{/images/error_image.jpg}"/>

这是我的项目结构:

project structure

使用ctrl悬停在一张照片上会将我定向到一张照片,所以路径很好。

link

但是我一直都看到这个:

error

image spring-boot thymeleaf src
1个回答
0
投票

[编辑]

问题在于下面的控制器方法,您应该在下面提供映射。

@GetMapping   // add mapping here
public String showSignUpForm()
{
    return "register";
}

请确保在您的末尾没有将静态资源配置为其他路径static/。如果您在application.properties中具有以下配置,请将其删除。

spring.resources.static-locations=

请确保application.properties中具有以下配置,spring boot的自动配置会将其设置为resource/static/

spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

这不是问题,但仍然将/images/更改为images/

<img src="../static/images/error_image.jpg" th:width="1000" th:src="@{images/error_image.jpg}"/>
© www.soinside.com 2019 - 2024. All rights reserved.