mybatis collection 对象自身关联

先看看代码

<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)

故而发表个人愚见,(还是得多看看官方文档),欢迎大家各种意见.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值