mybatis之Mapped Statements collection does not contain value for...错误原因分析

错误代码如下:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.java1234.mappers.AddressMapper.findById
### The error may exist in com/java1234/mappers/StudentMapper.xml
### The error may involve com.java1234.mappers.StudentMapper.findStudentWithAddress
### The error occurred while handling results
### SQL: select * from t_student t1,t_address t2 where t1.addressId=t2.id and t1.id=?
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.java1234.mappers.AddressMapper.findById
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy6.findStudentWithAddress(Unknown Source)
...

错误原因有以下几种:

1、mapper.xml中没有加入namespace; 
2、mapper.xml中的方法和接口mapper的方法不对应; 
3、mapper.xml没有加入到mybatis-config.xml中(即总的配置文件);
4、mapper.xml文件名和所写的mapper名称不相同。


你可能感兴趣的:(MyBatis)