我有一个命名的文件夹uploads是在同一级别的src文件夹中。我将图像上传到此文件夹。然后我添加了以下配置以便能够在 thymeleaf 中提供图像:@Configurationpublic 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.显然我配置中的路径是错误的。有人可以告诉我我做错了什么吗?
1 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
有缺失file。添加以下配置:
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/images/**")
.addResourceLocations("file:resources/", "file:uploads/")
.setCachePeriod(0);
}
}
添加回答
举报
0/150
提交
取消