广告
返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot找不到映射文件的处理方式
  • 245
分享到

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

2024-04-02 19:04:59 245人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

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

SpringBoot找不到映射文件

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

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/** # 访问路径

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: SpringBoot找不到映射文件的处理方式

本文链接: https://www.lsjlt.com/news/168819.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作