mybatis返回带有重复条目的结果映射

Zun*_*med 3 mybatis

我使用mybatis从DB检索数据,返回的数据包含重复的条目.

必需结果:列名称,值

预期的结果是:column1值A但是返回的结果是:COLUMN1值A,column1值A.

希望能够澄清我的怀疑.

谁能告诉我为什么会这样?

<select id="getContentMap" resultType="map" parameterType="map">
            select planId,location_qualifier  from disclaimer_disclosure_content where 
            <choose>
                <when test="plan_id != null">
                    plan_id = #{plan_id}
                </when>
                <when test="product_id != null">
                    product_id = #{product_id}
                </when>
                <otherwise>
                    issuer_id = #{issuer_id}
                </otherwise>
            </choose>
             and effective_date >= #{effective_date} 
             and location_qualifier LIKE  CONCAT('%' , #{location_qualifier} , '%') 
        </select>
Run Code Online (Sandbox Code Playgroud)

quu*_*x00 5

您看到的问题是MyBatis 3中的错误,直到3.0.6版本:http://code.google.com/p/mybatis/issues/detail?id = 303.

在那个版本之后,你会得到我在其他答案中概述的答案(使用MyBatis 3.1.1完成).

您有四种选择:

  1. 只需忽略它,只抓住大写或小写条目
  2. 升级到至少3.0.6
  3. 停止使用map作为resultType并移动到POJO域对象
  4. 使用下面的解决方法:

MyBatis的解决方法<3.0.6

使用完整的大写列别名,它们只会在地图中显示一次(以大写形式显示):

<select id="getContentMap" resultType="map" parameterType="map">
  select plan_id as PLAN_ID, location_qualifier as LOCATION_QUALIFIER from disclaimer_disclosure_content
  where
  <!-- SNIP: is the same as you had -->
</select>
Run Code Online (Sandbox Code Playgroud)

这导致输出:

{PLAN_ID=2, LOCATION_QUALIFIER=Bar}
Run Code Online (Sandbox Code Playgroud)

(或类似的东西取决于你的选择看起来如何).