项目启动时报错: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