我使用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)
您看到的问题是MyBatis 3中的错误,直到3.0.6版本:http://code.google.com/p/mybatis/issues/detail?id = 303.
在那个版本之后,你会得到我在其他答案中概述的答案(使用MyBatis 3.1.1完成).
您有四种选择:
使用完整的大写列别名,它们只会在地图中显示一次(以大写形式显示):
<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)
(或类似的东西取决于你的选择看起来如何).
| 归档时间: |
|
| 查看次数: |
4330 次 |
| 最近记录: |