源码:
<select id="getCouponListByUserId" resultMap="getCouponListByUserId"> select * from campus_user_coupon uc left join campus_coupon c on uc.coupon_id=c.id where uc.campus_user_id=#{campusUserId} </select> <resultMap id="getCouponListByUserId" type="com.jipaocampus.jipao_campus.dto.ResCampusCouponDto" autoMapping="true"> <id column="campus_user_id" property="campusUserId"/> <collection property="campusCoupons" javaType="com.jipaocampus.jipao_campus.pojo.CampusCoupon" ofType="list" autoMapping="true"> <id property="id" column="id"/> </collection> </resultMap>
报错内容:
### Error querying database. Cause: java.lang.UnsupportedOperationException
### The error may exist in file [D:\Desktop\xiaoyuantong\jipaoxiaoyuan-server2.0\jipao_school\jipao_campus\target\classes\mapper\CampusCouponMapper.xml]
### The error may involve com.jipaocampus.jipao_campus.mapper.CampusCouponMapper.getCouponListByUserId
### The error occurred while handling results
### SQL: select * from campus_user_coupon uc left join campus_coupon c on uc.coupon_id=c.id where uc.campus_user_id=?
### Cause: java.lang.UnsupportedOperationException] with root cause
错误原因:
一对多关系映射中,javaType是子对象的Java类型,ofType是返回数据类型
解决方法:
<collection property="campusCoupons" javaType="com.jipaocampus.jipao_campus.pojo.CampusCoupon" ofType="list" autoMapping="true"> <id property="id" column="id"/> </collection>
此代码中,将javaType值改为List,ofType值改为com.jipaocampus.jipao_campus.pojo.CampusCoupon
改后:
<collection property="campusCoupons" javaType="List" ofType="com.jipaocampus.jipao_campus.pojo.CampusCoupon" autoMapping="true"> <id property="id" column="id"/> </collection>