关于BindingException报错卡在了奇怪的地方
最近刚做了一个新项目,但是在第一增删改查就报错了,自己校对了一遍,又在网上查了 一遍,大多是说:
校验mapper接口和mapper.xml文件名是否相同
校验namespace是否是mapper接口的对应路径
校验sql语句的id是否和mapper接口的方法对应
然后我又查到了一个新思路,
idea开发maven项目中src源代码下的xml等资源文件编译进classes文件夹,
注意:如果没有这个,它会自动搜索resources下是否有mapper.xml文件,
如果没有就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
我的mapper.xml文件在resource下所以不会有上述问题,所以没有什么用处
然后我看了一眼我的配置文件O.O,哦,问题找到了,配置文件少了一行
mybatis.mapper-locations=classpath:mapper/*.xml