MyBatis中collection (一对一,一对多)

MyBatis学习http://www.mybatis.org/mybatis-3/zh/index.html

大对象InsuranceDetailsVO:

com.quicksure.mobile.entity.InsuranceDetailsVO

public
class InsuranceDetailsVO { private String orderno; @Resource private Baseinfor baseinfor; @Resource private Coverageinfor coverageinfor; private List<Coverageinfor> coverageinfors; //险种的集合 ........其它无关实体类和get、set方法省略 }

 

实体类Baseinfor:

com.quicksure.mobile.entity.Baseinfor

public
class Baseinfor { private String orderno;// 订单号 ......一些基本的字段和get、set方法 }

 

对应的mapper:

联合查询,一对一
<
mapper namespace="com.quicksure.mobile.dao.VelicheBatchCheckMapper"> <resultMap id="queryBatchPolicy" type="com.quicksure.mobile.entity.InsuranceDetailsVO"> <id column="orderNo" jdbcType="VARCHAR" property="orderno" /> <collection property="baseinfor" ofType="com.quicksure.mobile.entity.Baseinfor" resultMap="baseinforResult"></collection> </resultMap>
联合查询,一对多 <resultMap id="queryBatchPolicy1" type="com.quicksure.mobile.entity.InsuranceDetailsVO"> <id column="orderNo" jdbcType="VARCHAR" property="orderno" /> <collection property="baseinfor" ofType="com.quicksure.mobile.entity.Baseinfor" resultMap="baseinforResult"></collection> <collection property="coverageinfors" ofType="com.quicksure.mobile.entity.Coverageinfor" resultMap="coverageinforResult"></collection> </resultMap>
<resultMap id="baseinforResult" type="com.quicksure.mobile.entity.Baseinfor">
  ......基本字段映射
</resultMap>

<resultMap id="coverageinforResult" type="com.quicksure.mobile.entity.Coverageinfor">
  ......基本字段映射
</resultMap>

<!-- CSR导出excel时查询对应的数据 --> <select id="CSRExportExcel" parameterType="java.util.Map" resultMap="queryBatchPolicy1"> select baseinfor.orderNo,baseinfor.syapplicationNo,baseinfor.jqapplicationNo,baseinfor.sypolicyNo,baseinfor.jqpolicyNo, baseinfor.deptAddress,vhinfor.drvOwner,vhinfor.lcnNo,baseinfor.sypolicyStartDate,baseinfor.jqpolicyStartDate, baseinfor.orderstate,baseinfor.syPremium,baseinfor.jqPremium,baseinfor.taxPremium,baseinfor.totalPremium, baseinfor.updateTime,baseinfor.paymentMethod,baseinfor.jqpolicyNo,baseinfor.sypolicyNo,baseinfor.createTime, coverage.* from ludimb_baseinfor baseinfor LEFT JOIN ludimb_vhlinfor vhinfor on baseinfor.vhlinforId = vhinfor.vhiinforId LEFT JOIN ludimb_coverageinfor coverage on baseinfor.orderNo = coverage.baseinforOrderNo where 1=1 <if test="deptcode!=null and deptcode!='' and deptcode!=1"> and baseinfor.deptNo=#{deptcode} </if> <if test="orderNo!=null and orderNo!=''"> and baseinfor.orderNo=#{orderNo} </if> <if test="drvowner!=null and drvowner!=''"> and vhinfor.drvOwner=#{drvowner} </if> <if test="lcnNo!=null and lcnNo!=''"> and vhinfor.lcnNo=#{lcnNo} </if> <choose> <when test="orderstate==1"> and baseinfor.orderstate in (30,40) </when> <when test="orderstate==2"> and baseinfor.orderstate in (50,60,70) </when> <when test="orderstate==3"> and baseinfor.orderstate in (10,20) </when> <when test="orderstate==4"> and baseinfor.orderstate = 80 </when> <otherwise> </otherwise> </choose> <if test="createStartTime!=null and createStartTime!=''"> <![CDATA[ and baseinfor.createTime >= #{createStartTime} ]]> </if> <if test="createEndTime!=null and createEndTime!=''"> <![CDATA[ and baseinfor.createTime <= #{createEndTime} ]]> </if> </select>
<mapper>

 

转载于:https://www.cnblogs.com/ldbangel/p/6233806.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值