**Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.chenpeng.mapper.UsersMapper.selectByExample**
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:189)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:43)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
at com.sun.proxy.$Proxy8.selectByExample(Unknown Source)
at com.chenpeng.test.Test.main(Test.java:31)
今天使用IDEA创建了一个maven的web工程**,因为习惯了使用逆向工程,今天居然查询数据库的时候一直给我报这样的错误,接口,类,命名空间都检查了没问题,不知道到底是哪里有问题,而且逆向工程生成的Pojo和Mapper也不可能有问题,折腾半天,网上查阅资料,终于解决了。。。浪费了好长的时间**
如上图,我已经搭好环境了,jar包也已经引入了,一运行就报这样的错
可以看到Spring容器中的对象是可以取出来的,但是一运行接口绑定的方法,就报错
原来:
项目是maven项目,需要在编译后,到接口所在目录看一看,很有可能是没有生产对应的xml文件,因为maven默认是不编译的
果然一看:
真的没有mapper.xml文件,MyBatis-逆向工程生成的接口和接口的映射文件都放在一起了,难怪呢
需要加一段代码:
在pom.xml的里面,加这么一段:
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources
我们clean一下maven项目,加上上面这段话,重新看编译以后的文件
运行效果: