背景:
在练习mybatis的对象映射时,设置了一个嵌套查询
问题描述
问题:
结果在test时报错,拿不到gid列的映射:
@Test
public void test (){
StudentMapper mapper = session.getMapper(StudentMapper.class);
List students = mapper.listAllstudent();
System.out.println(students);
}
提示: Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection do
提示:java.lang.IllegalArgumentException:映射语句集合不包含com.ttt.mybatis.mapper.GradeMapper.listAllGrade 的值 ### mapper/StudentMapper.xml 中可能存在错误org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.ttt.mybatis.mapper.GradeMapper.listAllGrade ### The error may exist in mapper/StudentMapper.xml ### The error may involve com.ttt.mybatis.mapper.StudentMapper.listAllstudent ### The error occurred while handling results ### SQL: select id,name ,age, gid from student ### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.ttt.mybatis.mapper.GradeMapper.listAllGrade
原因分析:
分析:
其实就是映射语句集合没有正常执行
可能引起原因:
1、mapper配置文件没有加载到;
2、查看编译后文件(如果没有xml文件说明mybatis或者maven没有加载到)(小概率)
3、可能是sql的xml文件的 id属性绑定的值与方法的ID不相同
4、在配置mybatis-cofnig.xml文件时,没有添加mapper.xml配置文件的路径
解决:
我这里是因为在mybatis-cofnig.xml中没有添加后来加入的Grademapper.xml的路径:
// 加入
加入后解决。
暑期编程PK赛 得CSDN机械键盘等精美礼品!


