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

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题,

即在mybatis中dao层与mapper层文件在做映射绑定的时候,无法一一对应。接口找不到xml。

解决方案:

第一种:在你的pom.xml的build中,添加配置项.

<resourceS>
<resource>
     <directory>src/main/java</directory>
     <includes>
        <include>**/*.xml</include>
     </includes>
     <filtering>true</filtering>
</resource>

<resource>
     <directory>src/main/resources</directory>
     <includes>
     <include>**/*.*</include>
     </includes>
     <filtering>true</filtering>
</resource>

<resource>
    <directory>src/main/resources</directory>
    <includes>
       <include>application.yml</include>
    </includes>
    <filtering>true</filtering>
    <targetPath>BOOT-INF/classes</targetPath>
</resource>

</resourceS>

 

同时,需要在resources文件夹下的application.yml文件中,新增以下信息。

没有application.yml就自己新建一个,有application.perproties也行,只不过二者配置属性的方式不同,Springboot读取二者的优先级不同而已

mybatis:
  mapper-locations: classpath*:com/example/demo/**/*apper.xml

配置mapper-locations的时候,首先应该保证你的Mapper层的xml文件是以apper.xml文件结尾的。示例:StudentMapper.xml

如果你的Mapper层的xml文件的命名规范是以Dao结尾:StudentDao.xml,那么就设置如下:

mybatis:
  mapper-locations: classpath*:com/example/demo/**/*Dao.xml

当然原理上你也可以设置成

mybatis:
  mapper-locations: classpath*:com/example/demo/**/*.xml

但是如果你的项目中xml文件过多,还是建议使用apper.xml结尾的设置方式

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值