Result Maps collection does not contain value for XXXXX
在做mybatis多表查询的时候,出现了下面的错误:
java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.up.sell.mapper.system.AdvertisementMapper.areasResult at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:888) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:640) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNestedResultMap(DefaultResultSetHandler.java:1011) ~[mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:945) ~[mybatis-3.4.6.jar:3.4.6]
意思很明确,是ResultMap映射出现了问题,下面贴上映射代码:
<resultMap type="Advertisement" id="AdvertisementResult"> <id property="id" column="id" /> <result property="title" column="title" /> <result property="imgPath" column="img_path" /> <result property="url" column="url" /> <result property="description" column="description" /> <result property="sorrt" column="sorrt" /> <result property="place" column="place" /> <result property="provinceId" column="province_id" /> <result property="cityId" column="city_id" /> <result property="advFlag" column="adv_flag" /> <result property="createUser" column="create_user" /> <result property="createTime" column="create_time" /> <result property="updateUser" column="update_user" /> <result property="updateTime" column="update_time" /> <association property="provinceId" column="id" javaType="Areas" resultMap="areasResult"/> </resultMap>
我的sql代码:
<select id="findList" parameterType="Advertisement" resultMap="AdvertisementResult"> SELECT a.id , a.title , a.img_path , a.url , a.description , a.sort , s.area_name , s1.short_name FROM advertisement a LEFT JOIN areas s ON a.province_id = s.id LEFT JOIN areas s1 on a.city_id = s1.id </select>
我是把关联表的resultMap忘记写了,加上之后就好了,代码如下:
<resultMap id="areasResult" type="Areas"> <id property="id" column="id" /> <result property="areaName" column="area_name" /> <result property="parentId" column="parent_id" /> <result property="shortName" column="short_name" /> </resultMap>
主表的resultMap和副表的resuleMap Id是对应的。