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>