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>
MyBatis中collection (一对一,一对多)的更多相关文章
- mybatis中collection和association的作用以及用法
deptDaoMapper.xml 部门对应员工(1对多的关系) <resultMap type="com.hw.entity.Dept" id="deptinfo ...
- mybatis中实现一对一,一对多查询
在实际的开发中我们经常用到的是一对一查询和一对多查询.而多对多的实现是通过中间来实现,这里就没有给出来了 比如: 订单和用户是一对一的关系(一个订单只能对应一个用户) 订单和订单明细是一对多的关系(一 ...
- MyBatis的关联关系 一对一 一对多 多对多
一对一示例 一个妻子对应一个丈夫 数据库表设计时 在妻子表中添加一个丈夫主键的作为外键 1 对应的JavaBean代码虽然在数据库里只有一方配置的外键,但是这个一对一是双向的关系. Husband实体 ...
- Mybatis中collection和association的使用区别
1. 关联-association2. 集合-collection 比如同时有User.java和Card.java两个类 User.java如下: public class User{ privat ...
- Mybatis中 collection 和 association 的区别
public class A{ private B b1; private List<B> b2;} 在映射b1属性时用association标签,(一对一的关系) 映射b2时用colle ...
- Mybatis中 collection 和 association 的区别?
public class A{ private B b1; private List<B> b2;} 在映射b1属性时用association标签,(一对一的关系) 映射b2时用colle ...
- mybatis中collection association优化使用及多参数传递
mybatis都会用,但要优雅的用就不是那么容易了 今天就简单举例,抛砖引玉,供大家探讨 1.主表 CREATE TABLE `test_one` ( `id` int(11) NOT NULL AU ...
- Mybatis中collection与association的区别
association是多对一的关系 collection是一个一对多的关系
- mybatis中collection子查询注入参数为null
具体实现参照网上,但是可能遇到注入参数为null的情况,经过查阅及自己测试记录一下: 子查询的参数中,有<if test="">之类,需要指定别名,通过 http:// ...
随机推荐
- 如何在虚拟机安装桌面Ubuntu
本篇仅为作业... 实验课程:Linux 实验机器:联想y410p 指导老师:刘臣奇 实验时间:2016年10月12日 学生学号:140815 姓名:杨文乾 一.新建一个虚拟机,按照之前建立虚拟机的步 ...
- Java并发编程:volatile关键字解析
Java并发编程:volatile关键字解析 volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在 ...
- JDK1.8 HashMap 源码分析
一.概述 以键值对的形式存储,是基于Map接口的实现,可以接收null的键值,不保证有序(比如插入顺序),存储着Entry(hash, key, value, next)对象. 二.示例 public ...
- 使用 SSH上传安装tomcat
开发步骤: 1.在soft文件夹下上传tomcat 2.[root@localhost soft]# tar -zxvf apache-tomcat-7.0.61.tar.gz //解压安装 ...
- 《连载 | 物联网框架ServerSuperIO教程》- 3.设备驱动介绍
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- JHipster框架的简要搭建与说明
JHipster的亮点 风头超劲,席卷欧美,最新全能Java Web开发程式产生器 (java web generator). 由Java专家累积的开发经验,配上各类实用的框架技术,去繁取精的运用,全 ...
- SpringMVC+Spring+MyBatis+Maven调整【转】
Idea SpringMVC+Spring+MyBatis+Maven整合 创建项目 File-New Project 选中左侧的Maven,选中右侧上方的Create from archetyp ...
- html中role的作用
role 是增强语义性,当现有的HTML标签不能充分表达语义性的时候,就可以借助role来说明. 通常这种情况出现在一些自定义的组件上,这样可增强组件的可访问性.可用性和可交互性. role的作用是描 ...
- 自己实现一个简易web服务器
一个web服务器是网络应用中最基础的环节. 构建需要理解三个内容: 1.http协议 2.socket类 3.服务端实现原理 1.1 HTTP http请求 一般一个http请求包括以下三个部分: 1 ...
- 苹果的MDM简介
MDM(Mobile Device Management)移动设备管理,一般会用于企业管理其移动设备,鉴于iOS是比较封闭的系统很多的功能都难以实现,所以利用苹果的MDM可以达到远程控制设备,像远程定 ...