欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

SpringBoot找不到映射文件

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

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

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

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

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

SpringBoot映射本地文件到URL路徑

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

1、使用配置類

需要一個(gè)配置類,實(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é)尾,在訪問(wèn)時(shí)否需要把在最后一個(gè)文件夾名添加在映射路徑后面
? ? // 如:
? ? // locationPath-->F:\img\ ? ?? ?訪問(wèn)路徑-->ip:port/img/1.png
?? ?// locationPath-->F:\img ? ?? ??? ?訪問(wèn)路徑-->ip:port/img/img/1.png
?? ?// locationPath-->F:\img\123\ ?? ?訪問(wèn)路徑-->ip:port/img/1.png
?? ?// locationPath-->F:\img\123 ??? ?訪問(wèn)路徑-->ip:port/img/123/1.png
?? ?
? ? @Override
? ? public void addResourceHandlers(ResourceHandlerRegistry registry) {
? ? ?? ?// 目前在本地Win系統(tǒng)測(cè)試需要在本地路徑前添加 "file:"
? ? ?? ?// 有待確認(rèn)Linux系統(tǒng)是否需要添加(已確認(rèn))
? ? ?? ?// Linux系統(tǒng)也可以添加 "file:"
? ? ?? ?registry.addResourceHandler(netPath).addResourceLocations("file:"+locationPath);
? ? }
}

2、在配置文件yml中配置

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

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

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

相關(guān)文章

最新評(píng)論