我有一個命名的文件夾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
提交
取消