先看看代码
<resultMap id="baseResultMap" type="com.mysql.ForumCommentBean">
<id column="ID" property="id" jdbcType="CHAR" />
<collection column="parentId" property="subComments" ofType="com.mysql.ForumCommentBean">
<result column="subCommentTm" property="commentTm" jdbcType="TIMESTAMP" />
</collection>
</resultMap>
<select id="getComments" parameterType="java.lang.String" resultMap="baseResultMap">
SELECT comm.id,subComm.commentTm subCommentTm
FROM forum_comment comm,forum_comment subComm
WHERE subComm.parentId = comm.id
AND comm.articleId = #{articleId}
</select>
<resultMap id="detailResultMap" type="com.mysql.GoodsBean">
<id column="id" property="id" jdbcType="VARCHAR" />
<collection column="refId" property="images" javaType="ArrayList"
ofType="com.mysql.ImagesBean"
resultMap="com.mysql.ImagesMapper.baseResultMap" />
<collection column="pid" property="subGoods" ofType="com.mysql.GoodsBean">
<id column="subId" property="id" jdbcType="VARCHAR" />
</collection>
</resultMap>
前段时间,遇到过collection标记中column属性值与result父节点column属性值相同导致查询结果出问题,
故推测mybatis中查询语句与resultMap中应是以column属性与查询语句别名进行配对(- -原谅一个刚刚涉入 mybatis的green hand)
之前有看他人写过关于mybatis的自身关联collection配置的文章(参见:http://lyl290932857.iteye.com/blog/1472814)
故而发表个人愚见,(还是得多看看官方文档),欢迎大家各种意见.