mybitis 查询返回结果有子集合

方式一:使用 collection 标签

如下:

<resultMap type="com.domain.a" id="OrderMap">
<id column="id" jdbcType="INTEGER" property="orderId" />
<result column="order_number" jdbcType="VARCHAR" property="orderNumber" />
<result column="order_time" jdbcType="TIMESTAMP" property="orderTime" />
<collection property="orderDetails" ofType="cn.ljw.vo.OrderDetail" javaType="java.util.List">
<id column="detail_order_detail_id" jdbcType="INTEGER" property="orderDetailId" />
<result column="detail_order_id" jdbcType="INTEGER" property="orderId" />
<result column="detail_commodity_name" jdbcType="VARCHAR" property="commodityName" />
<result column="detail_commodity_number" jdbcType="INTEGER" property="commodityNumber" />
</collection>
</resultMap>

方式二:

<resultMap type="User" id="userMap">
<id column="u_id" property="id" />
<result column="username" property="username" />
<result column="age" property="age" />
<result column="address" property="address" />
<!--当表之间的关系是一对多时,用 collection--> <!-- 这里的 column="u_id"是为了传参数到嵌套的查询select="....."-->
<collection property="goodsList" ofType="Goods" column="u_id" select="com.leo.mapper.GoodsDao.selectGoodsForUser" />
</resultMap> <!--goodsList是User实体类中的 私有属性集合 -->

https://blog.csdn.net/liuao107329/article/details/41829767

https://www.cnblogs.com/iwenwen/p/11082972.html

猜你喜欢

转载自www.cnblogs.com/codefeng/p/12938080.html