association 关联其他表 报错 Mapped Statements collection does not contain value for xxx

mybatis mapper.xml 写关联查询 运用 resultmap 结果集中 用 association 关联其他表 并且 用 association 的 select 查询值 报错 java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for xxx

在学习用mybaits 的association写一个关联查询时,报错了Mapped Statements collection does not contain value for mapper.ClassMapper.getTeacher,查了网上的资源,发现没有能解决问题的。

我就只能去接一杯水,再检查一边代码,一个小时过去了,双眼发黑还是没能找到错,然后我又把报错一字不漏地看了一遍,咦,mapper.ClassMapper.getTeacher是什么,我的ClassMapper映射文件里没有getTeacher,它原本是在TeacherMapper里呀,这是怎么回事???

ClassMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="mapper.ClassMapper">
	<resultMap type="ClassEntity" id="classResultMap">
		<id column="classid" property="classid"/>
		<result column="classname" property="classname"/>
		<association property="teacherEntity" column="teacherid" select="getTeacher"/>
	</resultMap>
	<select id="getClassByID" parameterType="int" resultMap="classResultMap">
		select * from class c
		where c.classid=#{classid}
	</select>
</mapper>

TeacherMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="mapper.TeacherMapper">
	<resultMap type="TeacherEntity" id="teacherResultMap">
		<id column="teacherid" property="teacherid"/>
		<result column="teachername" property="teachername"/>
		<result column="teachersex" property="teachersex"/>
	</resultMap>
	<select id="getTeacher" parameterType="int" resultMap="teacherResultMap">
		select * from teacher t
		where t.teacherid=#{teacherid}
	</select>
</mapper>

是不是配置文件里没加mapper呢?

	<mappers>
        <mapper resource="mapper/ClassMapper.xml"/>
        <mapper resource="mapper/TeacherMapper.xml"/>
    </mappers>

加了的呀,但是getTeacher确实定义在TeacherMapper.xml里的,于是我把ClassMapper里的
(以下为原错误代码)

<association property="teacherEntity" column="teacherid" select="getTeacher"/>

修改为

<association property="teacherEntity" column="teacherid" select="mapper.TeacherMapper.getTeacher"/>

junit,大功告成~~~

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值