項目啟動時報錯:Result Maps collection already contains value for com.xxx.xxx.xx.mapper.XxxMapper.baseResultMap


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>
現在再次啟動服務器,就沒毛病了,原理我是真的不清楚,有木有大神指導一下下呢~

      




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM