Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.xxx.xxx.xx.mapper.XxxMapper.BaseResultMap
這個問題糾結了我一兩個小時, 百度里面的回答很多,但是每個人的錯誤坑不近相同,所以沒能解決問題
這是一個使用Mybatis逆向工程生成的一堆文件中的一個,這個錯很明顯在說dao的resources包下的xml文件中,出現了重復的 baseResultMap
<resultMap id="BaseResultMap" type="com.practise.pojo.Student">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="spec_name" property="specName" jdbcType="VARCHAR"/>
</resultMap>
然后下面的引用了兩次定義的這個 BaseResultMap
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.practise.pojo.student">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from tb_specification
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from tb_specification
where id = #{id,jdbcType=BIGINT}
</select>
但是我不知道為什么僅僅是引用了兩次都會報錯,我覺得很不科學,但是也無可奈何
這兩個不同的方法都得用這個返回的結果集吧 我就復制了一個ResultMap,不過換了個名字 -- 在后面加了個s,得到下面的效果
<resultMap id="BaseResultMaps" type="com.practise.pojo.Student">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="spec_name" property="specName" jdbcType="VARCHAR"/>
</resultMap>
<resultMap id="BaseResultMap" type="com.practise.pojo.Student">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="spec_name" property="specName" jdbcType="VARCHAR"/>
</resultMap>
<select id="selectByExample" resultMap="BaseResultMaps" parameterType="com.practise.pojo.student">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from tb_specification
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
select
<include refid="Base_Column_List"/>
from tb_specification
where id = #{id,jdbcType=BIGINT}
</select>
現在再次啟動服務器,就沒毛病了,原理我是真的不清楚,有木有大神指導一下下呢~