亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringBoot找不到映射文件的處理方式

 更新時間:2022年10月01日 11:10:59   作者:999感冒靈2000  
這篇文章主要介紹了SpringBoot找不到映射文件的處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

SpringBoot找不到映射文件

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.qf.mapper.UserM

如果xml文件配置都確認(rèn)無誤還不能解決的話,可以嘗試在pom.xml文件中進(jìn)行如下配置:

<build>
  <resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>
  </resources>
</build>

后面我發(fā)現(xiàn)在yml文件里面,下面第一種寫法不行,第二種又可以。。。

mapper-locations: com/tt/mapper/*.xml
mapper-locations: com.tt.mapper/*.xml

SpringBoot映射本地文件到URL路徑

有兩種方法,使用配置類,或者在配置文件yml中配置

1、使用配置類

需要一個配置類,實(shí)現(xiàn)了WebMvcConfigurer接口

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration // 1.添加配置文件注解
public class Config implements WebMvcConfigurer { // 2.實(shí)現(xiàn)WebMvcConfigurer接口
// ? ?@Value("${img.path}")
? ? private String locationPath = "F:\\img\\"; // 3.文件本地路徑
? ? private static final String netPath = "/img/**"; // 映射路徑
? ? // 目前發(fā)現(xiàn)如果本地路徑不是以分隔符結(jié)尾,在訪問時否需要把在最后一個文件夾名添加在映射路徑后面
? ? // 如:
? ? // locationPath-->F:\img\ ? ?? ?訪問路徑-->ip:port/img/1.png
?? ?// locationPath-->F:\img ? ?? ??? ?訪問路徑-->ip:port/img/img/1.png
?? ?// locationPath-->F:\img\123\ ?? ?訪問路徑-->ip:port/img/1.png
?? ?// locationPath-->F:\img\123 ??? ?訪問路徑-->ip:port/img/123/1.png
?? ?
? ? @Override
? ? public void addResourceHandlers(ResourceHandlerRegistry registry) {
? ? ?? ?// 目前在本地Win系統(tǒng)測試需要在本地路徑前添加 "file:"
? ? ?? ?// 有待確認(rèn)Linux系統(tǒng)是否需要添加(已確認(rèn))
? ? ?? ?// Linux系統(tǒng)也可以添加 "file:"
? ? ?? ?registry.addResourceHandler(netPath).addResourceLocations("file:"+locationPath);
? ? }
}

2、在配置文件yml中配置

該方法沒有使用配置類的方法中,因本地路徑不是以分隔符結(jié)尾而造成的訪問問題

# 文件本地路徑
img:
? # ?path: /root/RandomImg/images/ ? ? #Linux
? path: F:\img\ ? ? ?#Win
# 映射路徑
spring:
? resources: ? ? #訪問系統(tǒng)外部資源,將該目錄下的文件映射到系統(tǒng)下
? ? static-locations: classpath:/static/, file:${img.path} #本地文件,多個路徑用英文逗號隔開
? mvc:
? ? static-path-pattern: /img/** # 訪問路徑

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論