我有一个命名的文件夹uploads是在同一级别的src文件夹中。我将图像上传到此文件夹。然后我添加了以下配置以便能够在 thymeleaf 中提供图像:
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/uploads/**")
.addResourceLocations("/resources/","/../../uploads/")
.setCachePeriod(0);
}
}
我尝试像这样在 Thymeleaf 中提供图像:
<img class="img-thumbnail img-responsive" src="#" th:src="@{'/uploads/' + ${photo}}" alt="">
${photo}名称文件名在哪里。
但是我收到以下错误:
The resource path [/../../uploads/rtf_vtvsq1r12q.png] has been normalized to [null] which is not valid.
显然我配置中的路径是错误的。有人可以告诉我我做错了什么吗?
慕哥9229398
相关分类