mybatis一对多

来源:互联网 发布:千岛湖惨案 知乎 编辑:程序博客网 时间:2024/04/27 19:48

BusRedPacketModel:红包表(一)

BusRedPacketHisModel:红包记录表(二)

关联字段:redId奖励记录

mapper中配置:

<resultMap type="BusRedPacketModel" id="busRedPacket">
<result column="redId" property="redId"/>

BusRedPacketModel信息  表(t_bus_red_packet)
<collection property="hisList" ofType="BusRedPacketHisModel" column="redId">  
           BusRedPacketHisModel信息 表(t_bus_red_packet_his)
        </collection>  
</resultMap>

查询

<select id="selectBusRedPacket" parameterType="java.util.Map" resultMap="busRedPacket">
select  from t_bus_red_packet t,t_bus_red_packet_his h
where t.redId=h.redId and t.userId=#{userId} 
</select>

两个类中一里面是集合,多中事实体

0 0