1.出现异常
Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.xc.dao.BookMapper.mapper_resultMap[BookBean]_association[category]
at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:782)at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:754)
at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:536)
at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:207)
at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:284)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.processNestedResultMappings(XMLMapperBuilder.java:383)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildResultMappingFromContext(XMLMapperBuilder.java:363)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:279)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:251)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:243)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
... 48 more
2.原始代码
<resultMap type="com.xc.domain.Book" id="BookBean">
<id column="book_id" property="book_id"/><result column="book_name" property="book_name"/>
<result column="category_id" property="category_id"/>
<result column="book_isbn" property="book_isbn"/>
<result column="orderPbook_idrice" property="book_autor"/>
<result column="book_autor" property="book_pubhouse"/>
<result column="book_page" property="book_page"/>
<result column="book_state" property="book_state"/>
<result column="book_inDate" property="book_inDate"/>
<result column="book_borrownum" property="book_borrownum"/>
<result column="others" property="others"/>
<!-- 多对一的关系 -->
<!--column:指外键值, property: 指的是属性的值, javaType:指的是属性的类型-->
<association property="category" javaType="com.xc.domain.Category">
<id column="category_id" property="category_id"/>
<result column="category_name" property="category_name"/>
<result column="category_case" property="category_case"/>
</association>
</resultMap>
<select id="bookFindAll" parameterType="QueryVo" resultType="BookBean">
select a.*,b.category_name from book a,category b where a.category_id = b.category_id
<!-- <include refid="user_Where"></include>
<if test="type != null and type != ''">
order by ${type} asc
</if> -->
</select>
3.修改后代码
<resultMap type="com.xc.domain.Book" id="BookBean">
<id column="book_id" property="book_id"/>
<result column="book_name" property="book_name"/>
<result column="category_id" property="category_id"/>
<result column="book_isbn" property="book_isbn"/>
<result column="orderPbook_idrice" property="book_autor"/>
<result column="book_autor" property="book_pubhouse"/>
<result column="book_page" property="book_page"/>
<result column="book_state" property="book_state"/>
<result column="book_inDate" property="book_inDate"/>
<result column="book_borrownum" property="book_borrownum"/>
<result column="others" property="others"/>
<!-- 多对一的关系 -->
<!--column:指外键值, property: 指的是属性的值, javaType:指的是属性的类型-->
<association property="category" javaType="com.xc.domain.Category">
<id column="category_id" property="category_id"/>
<result column="category_name" property="category_name"/>
<result column="category_case" property="category_case"/>
</association>
</resultMap>
<select id="bookFindAll" parameterType="QueryVo" resultMap="BookBean">
select a.*,b.category_name from book a,category b where a.category_id = b.category_id
<!-- <include refid="user_Where"></include>
<if test="type != null and type != ''">
order by ${type} asc
</if> -->
</select>