org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)新的异常解决方案

在做springboot和mybatis的整合案例时,就是一个简单的到数据库查询数据的操作,发现竟然处理了如标题的异常,无法查询出想要的数据,mapper接口和mapper映射文件无法对应,通过查找资料,有以下解决办法:

首先:我出现的异常:

我的mapper接口和mapper映射文件的位置:

异常的分析:

  出现异常后,我用debug进行调试,发现请求能到controller层,在service层出现了异常:

解决方案:

1. 在application.yml中配置

mapper-locations: classpath:mapper/*.xml     用来在target目录下找到mapper映射文件的

配置了之后,当程序运行时就会在.class文件目录找到对应的mapper映射文件:

再次访问的结果:

2. 第二种方法:

将mapper映射文件和mapper接口放在同一个包下面:

在pom.xml文件种加入以下部分:主要是mapper.xml文件IDEA运行时无法编译,添加之后,IDEA就可以将mapper.xml文件编译,mapper接口也就能找到了mapper映射文件了。

在pom.xml中添加代码如下:
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

访问结果如下:http://localhost/hello/1

注意:只是讲解了我认为重要的点,一些基本的注解配置什么的就不讲了,希望对你有用。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)是MyBatis访问报错的一种情况。这个错误通常出现在执行SQL语句时找不到对应的映射语句时。 解决这个问题的步骤如下: 1. 首先,确保你的Mapper接口和XML文件中的namespace一致。你可以按住Ctrl键点击接口,看是否能跳转到对应的XML文件。如果不能跳转,说明namespace不正确。 2. 检查主启动类上是否标注了@MapperScan注解,并且注解的参数是mapper接口所在包的全包名。或者,你也可以在Mapper接口上标注@Mapper注解。但是注意,这两者不能同时使用。 通过这些步骤,你应该能够解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)的问题。如果问题仍然存在,请确保你的SQL语句在XML文件中被正确定义,并且没有拼写错误或者其他语法错误。如果还有其他问题,可以提供更多的错误信息或者代码片段,以便更好地帮助你解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)...](https://blog.csdn.net/weixin_34402408/article/details/86024348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【报错解决】org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)](https://blog.csdn.net/qq_50914927/article/details/127091350)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值