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. sql将查询的结果集一次性插入到表变量中

    sql代码: declare @Subject table (--题目表变量 SubjectID int, Question nvarchar(MAX), CorrectAnswer ), Expla ...

  2. 同步辅助类CountDownLatch用法

    CountDownLatch是一个同步辅助类,犹如倒计时计数器,创建对象时通过构造方法设置初始值,调用CountDownLatch对象的await()方法则使当前线程处于等待状态,调用countDow ...

  3. 计算(LnN!)的值

    import java.util.*;import java.math.*;public class CaculatorLnN { public static void main(String[] a ...

  4. Mysql性能优化三(分表、增量备份、还原)

    接上篇Mysql性能优化二 对表进行水平划分 如果一个表的记录数太多了,比如上千万条,而且需要经常检索,那么我们就有必要化整为零了.如果我拆成100个表,那么每个表只有10万条记录.当然这需要数据在逻 ...

  5. HTML中的标记-遁地龙卷风

    第三版 上一版本在未经验证的情况下,盲目的认为很多东西是那样,造成错误,非常抱歉. 0.什么是标记 <input type="checkbox" checked />& ...

  6. Atitit 衡量项目的规模

    Atitit 衡量项目的规模 1. 预估衡量项目的规模的方法1 1.1. 方法一.Delphi 法1 1.2. 方法二. 类比法1 1.3. 方法三.功能点估计法1 1.4. 方法四.PERT估计法2 ...

  7. Google C++单元测试框架GoogleTest---值参数化测试

    值参数化测试允许您使用不同的参数测试代码,而无需编写同一测试的多个副本. 假设您为代码编写测试,然后意识到您的代码受到布尔参数的影响. TEST(MyCodeTest, TestFoo) { // A ...

  8. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  9. 手游录屏直播技术详解 | 直播 SDK 性能优化实践

    在上期<直播推流端弱网优化策略 >中,我们介绍了直播推流端是如何优化的.本期,将介绍手游直播中录屏的实现方式. 直播经过一年左右的快速发展,衍生出越来越丰富的业务形式,也覆盖越来越广的应用 ...

  10. C语言运算符优先级

    优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右 -- () 圆括号 (表达式)/函数名(形参表) -- . 成员选择(对象) 对象.成员名 -- ...