SpringBoot应用中如何解决无法找到映射文件的问题?

2026-05-25 21:281阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计632个文字,预计阅读时间需要3分钟。

SpringBoot应用中如何解决无法找到映射文件的问题?

目录:SpringBoot找不到映射文件

1. 使用配置类

2.在配置文件yml中配置

3.SpringBoot找不到映射文件异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

目录
  • SpringBoot找不到映射文件
  • SpringBoot映射本地文件到URL路径
    • 1、使用配置类
    • 2、在配置文件yml中配置

SpringBoot找不到映射文件

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

SpringBoot应用中如何解决无法找到映射文件的问题?

如果xml文件配置都确认无误还不能解决的话,可以尝试在pom.xml文件中进行如下配置:

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

后面我发现在yml文件里面,下面第一种写法不行,第二种又可以。。。

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

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

SpringBoot映射本地文件到URL路径

有两种方法,使用配置类,或者在配置文件yml中配置

1、使用配置类

需要一个配置类,实现了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.实现WebMvcConfigurer接口 //    @Value("${img.path}")     private String locationPath = "F:\\img\\"; // 3.文件本地路径     private static final String netPath = "/img/**"; // 映射路径     // 目前发现如果本地路径不是以分隔符结尾,在访问时否需要把在最后一个文件夹名添加在映射路径后面     // 如:     // 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系统测试需要在本地路径前添加 "file:"         // 有待确认Linux系统是否需要添加(已确认)         // Linux系统也可以添加 "file:"         registry.addResourceHandler(netPath).addResourceLocations("file:"+locationPath);     } }

2、在配置文件yml中配置

该方法没有使用配置类的方法中,因本地路径不是以分隔符结尾而造成的访问问题

# 文件本地路径 img:   #  path: /root/RandomImg/images/     #Linux   path: F:\img\      #Win # 映射路径 spring:   resources:     #访问系统外部资源,将该目录下的文件映射到系统下     static-locations: classpath:/static/, file:${img.path} #本地文件,多个路径用英文逗号隔开   mvc:     static-path-pattern: /img/** # 访问路径

以上为个人经验,希望能给大家一个参考,也希望大家多多支持自由互联。

标签:处理方式

本文共计632个文字,预计阅读时间需要3分钟。

SpringBoot应用中如何解决无法找到映射文件的问题?

目录:SpringBoot找不到映射文件

1. 使用配置类

2.在配置文件yml中配置

3.SpringBoot找不到映射文件异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

目录
  • SpringBoot找不到映射文件
  • SpringBoot映射本地文件到URL路径
    • 1、使用配置类
    • 2、在配置文件yml中配置

SpringBoot找不到映射文件

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

SpringBoot应用中如何解决无法找到映射文件的问题?

如果xml文件配置都确认无误还不能解决的话,可以尝试在pom.xml文件中进行如下配置:

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

后面我发现在yml文件里面,下面第一种写法不行,第二种又可以。。。

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

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

SpringBoot映射本地文件到URL路径

有两种方法,使用配置类,或者在配置文件yml中配置

1、使用配置类

需要一个配置类,实现了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.实现WebMvcConfigurer接口 //    @Value("${img.path}")     private String locationPath = "F:\\img\\"; // 3.文件本地路径     private static final String netPath = "/img/**"; // 映射路径     // 目前发现如果本地路径不是以分隔符结尾,在访问时否需要把在最后一个文件夹名添加在映射路径后面     // 如:     // 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系统测试需要在本地路径前添加 "file:"         // 有待确认Linux系统是否需要添加(已确认)         // Linux系统也可以添加 "file:"         registry.addResourceHandler(netPath).addResourceLocations("file:"+locationPath);     } }

2、在配置文件yml中配置

该方法没有使用配置类的方法中,因本地路径不是以分隔符结尾而造成的访问问题

# 文件本地路径 img:   #  path: /root/RandomImg/images/     #Linux   path: F:\img\      #Win # 映射路径 spring:   resources:     #访问系统外部资源,将该目录下的文件映射到系统下     static-locations: classpath:/static/, file:${img.path} #本地文件,多个路径用英文逗号隔开   mvc:     static-path-pattern: /img/** # 访问路径

以上为个人经验,希望能给大家一个参考,也希望大家多多支持自由互联。

标签:处理方式