Python 官方文档:入门教程 => 点击学习
目录SpringBoot找不到映射文件springBoot映射本地文件到URL路径1、使用配置类2、在配置文件yml中配置SpringBoot找不到映射文件 org.apache.i
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.qf.mapper.UserM
如果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
有两种方法,使用配置类,或者在配置文件yml中配置
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);
}
}
该方法没有使用配置类的方法中,因本地路径不是以分隔符结尾而造成的访问问题
# 文件本地路径
img:
# path: /root/RandomImg/images/ #Linux
path: F:\img\ #Win
# 映射路径
spring:
resources: #访问系统外部资源,将该目录下的文件映射到系统下
static-locations: classpath:/static/, file:${img.path} #本地文件,多个路径用英文逗号隔开
mvc:
static-path-pattern: /img/** # 访问路径
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: SpringBoot找不到映射文件的处理方式
本文链接: https://www.lsjlt.com/news/168819.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0