亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

spring boot - 從 src 外的文件夾提供圖像

spring boot - 從 src 外的文件夾提供圖像

海綿寶寶撒 2021-06-06 13:31:05
我有一個命名的文件夾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);

    }

}


查看完整回答
反對 回復 2021-06-10
  • 1 回答
  • 0 關注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號