mybatis错误:
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.xs.fun.admin.sql.dao.sql.mapper.*
错误截取
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.xs.fun.admin.sql.dao.sql.mapper.*(类省略,重点看错误提示)
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:672)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:507)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:500)
at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:240)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:71)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:39)
at com.sun.proxy.$Proxy12.selectByExample(Unknown Source)
at com.xs.fun.admin.sql.dao.SystemTrumpetDao.findByState(SystemTrumpetDao.java:54)
at com.xs.fun.admin.sql.service.SystemTrumpetService.findByState(SystemTrumpetService.java:45)
at com.xs.fun.admin.action.WorldChannelAction.getTrumpetList(WorldChannelAction.java:195)
... 29 more
出现这个错误基本就算是mapper接口与mapper.xml文件的问题
解决思路
不外乎以下几种情况:
1、没有使用<![CDATA[ XXXX ]]>语法,导致if语句引用的语法错误。
2、mapper.xml中没有加入namespace,或者是namespace对应的接口路径不对,那么此时也要注意对应的实体类路径是否正确
3、mapper.xml中的方法和接口mapper的方法不对应
4、mapper.xml没有加入到mybatis-config.xml中(即总的配置文件),例外:配置了mapper文件的包路径的除外
5、mapper.xml文件名和所写的mapper名称不相同。
以上5种经过排查基本上可以解决“Mapped Statements collection does not contain value for后面是什么类什么方法之类"的错误。
可能场景
1.迁移mapper接口、对应的实体类(推荐迁移后重新用mybatis逆向工程来一遍)
2.与spring集成后,没有配置扫描mapper.xml文件(配置好就可以)
3.mapper接口没有配置被扫描(配置好即可)
等等。。。