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>

MyBatis中collection (一对一,一对多)的更多相关文章

  1. mybatis中collection和association的作用以及用法

    deptDaoMapper.xml 部门对应员工(1对多的关系) <resultMap type="com.hw.entity.Dept" id="deptinfo ...

  2. mybatis中实现一对一,一对多查询

    在实际的开发中我们经常用到的是一对一查询和一对多查询.而多对多的实现是通过中间来实现,这里就没有给出来了 比如: 订单和用户是一对一的关系(一个订单只能对应一个用户) 订单和订单明细是一对多的关系(一 ...

  3. MyBatis的关联关系 一对一 一对多 多对多

    一对一示例 一个妻子对应一个丈夫 数据库表设计时 在妻子表中添加一个丈夫主键的作为外键 1 对应的JavaBean代码虽然在数据库里只有一方配置的外键,但是这个一对一是双向的关系. Husband实体 ...

  4. Mybatis中collection和association的使用区别

    1. 关联-association2. 集合-collection 比如同时有User.java和Card.java两个类 User.java如下: public class User{ privat ...

  5. Mybatis中 collection 和 association 的区别

    public class A{ private B b1; private List<B> b2;} 在映射b1属性时用association标签,(一对一的关系) 映射b2时用colle ...

  6. Mybatis中 collection 和 association 的区别?

    public class A{ private B b1; private List<B> b2;} 在映射b1属性时用association标签,(一对一的关系) 映射b2时用colle ...

  7. mybatis中collection association优化使用及多参数传递

    mybatis都会用,但要优雅的用就不是那么容易了 今天就简单举例,抛砖引玉,供大家探讨 1.主表 CREATE TABLE `test_one` ( `id` int(11) NOT NULL AU ...

  8. Mybatis中collection与association的区别

    association是多对一的关系 collection是一个一对多的关系

  9. mybatis中collection子查询注入参数为null

    具体实现参照网上,但是可能遇到注入参数为null的情况,经过查阅及自己测试记录一下: 子查询的参数中,有<if test="">之类,需要指定别名,通过 http:// ...

随机推荐

  1. react-native学习笔记--首次安装apk到小米5报错

    本文直接引用大神文档: [WINDOWS环境 React Native初识]com.android.ddmlib.InstallException: Failed to establish sessi ...

  2. Android 的进程和线程

    进程和线程 如果某个应用程序组件是第一次被启动,且这时应用程序也没有其他组件在运行,则android系统会为应用程序创建一个包含单个线程的linux进程.默认情况下,同一个应用程序的所有组件都运行在同 ...

  3. Struts2入门(二)——配置拦截器

    一.前言 之前便了解过,Struts 2的核心控制器是一个Filter过滤器,负责拦截所有的用户请求,当用户请求发送过来时,会去检测struts.xml是否存在这个action,如果存在,服务器便会自 ...

  4. 关于mysql 和Oracle的一大堆麻烦问题的解决方案

    [INS-20802] Oracle Net Configuration Assistant 失败 在百度上找了半天并没有找到可靠的解决方案,最后是可以安装完成的,之后我 通过SQL Plus连接就报 ...

  5. Web Worker javascript多线程编程(一)

    什么是Web Worker? web worker 是运行在后台的 JavaScript,不占用浏览器自身线程,独立于其他脚本,可以提高应用的总体性能,并且提升用户体验. 一般来说Javascript ...

  6. ES5概述(ECMAScript262/5.1)

    ES5概述(ECMAScript262/5.1) 本文参考:ES5概述 ECMAScript 是基于对象的: 基本语言和宿主设施都由对象提供,ECMAScript 程序是一组可通信的对象.ECMASc ...

  7. 服务器开启https协议

    开启Tomcat https服务 发布企业级应用的时候遇到一个问题,就是IOS7.1之后app的下载地址URL必须是https开头的协议,所以服务器必须支持https协议. 实验环境:Mac OSX ...

  8. ipad和iphone的适配

    关于xib或者storybord下iphone的横竖屏的适配以及ipad的适配 ios8出现了Size Classes,解决了各种屏幕适配的问题,他把屏幕的宽和高分别分成了三种,把屏幕总共分成了九种情 ...

  9. Java连接数据库的辣几句话

    Java连接数据库的辣几句话 1.java连接Oracle数据库 使用以下代码三个步骤: 1.下载ojdbc.jar包并导入项目中.附下载地址:http://download.csdn.net/det ...

  10. Eos开发——构造查询条件

    1.ajax 方式 var data = { orgid :orgid,year:year ,month: month,type:type,sortField:'sellEmpname' ,sortO ...