mybatis查询多条记录,只返回最后一条
小弟第一次用mybatis做项目,遇到个小问题,请教一下各位大神。。
<!-- 关系表关联元素表 -->
<resultMap type="Relation" id="relationJoinElementResultMap">
<result column="m_id" property="mId" />
<result column="s_id" property="sId" />
<association property="element" javaType="Element">
<result column="id" property="id" />
<result column="name" property="name" />
<result column="type" property="type" />
</association>
</resultMap>
<!-- 查询某元素下级的子元素 -->
<select id="getElementBelow" resultMap="relationJoinElementResultMap" parameterType="Relation">
SELECT a.m_id, a.s_id, b.id, b.name, b.type
FROM MD_RELATION a, MD_ELEMENT b
WHERE a.s_id=b.id
AND a.m_id=#{mId}
AND a.flag=0
AND b.flag=0
</select>
以上是mapper.xml中的部分配置,目前是可以运行的。调用该查询可以得到多条记录
现在遇到的问题是,如果select后面的列名只有部分,结果集却只返回最后一条
比如我把SQL写成
SELECT b.id, b.name, b.type
FROM MD_RELATION a, MD_ELEMENT b
WHERE a.s_id=b.id
AND a.m_id=#{mId}
AND a.flag=0
AND b.flag=0
这时就不会返回所有结果集
这个问题很困惑,难道select的列必须和对应的resultMap的元素数量一一对应吗?
多个select的时候,如果要共用一个resultMap,那么所有的列都要检索出来吗?或者每个select单独对应一个resultMap?
可否有只返回部分列的办法?