我想在我的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}"/>
这是我的项目结构:
使用ctrl悬停在一张照片上会将我定向到一张照片,所以路径很好。
但是我一直都看到这个:
[编辑]
问题在于下面的控制器方法,您应该在下面提供映射。
@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}"/>