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:// ...
随机推荐
- 设计模式(十三)代理模式(Proxy Pattern)
一.引言 在软件开发过程中,有些对象有时候会由于网络或其他的障碍,以至于不能够或者不能直接访问到这些对象,如果直接访问对象给系统带来不必要的复杂性,这时候可以在客户端和目标对象之间增加一层中间层,让代 ...
- TypeSDK总体设计思路和架构
引言:本文旨在提供读者制作一个自己的聚合SDK的思路,抛砖引玉,让更多的读者对聚合SDK有好的理解. 这是最好的时代,这是最坏的时代,这是智慧的时代,这是愚蠢的时代:这是信仰的时期,这是怀疑的时期:这 ...
- 物联网框架SuperIO 2.2.9和ServerSuperIO 2.1同时更新,更适用于类似西门子s7-200发送多次数据,才能读取数据的情况
一.解决方案 二.更新内容 1.修改IRunDevice接口,把void Send(io,bytes)改成int Send(io,bytes).2.修改网络控制器,发送数据不直接使用IO实例,改为使用 ...
- entityframework学习笔记--006-表拆分与实体拆分
1.1 拆分实体到多张表 假设你有如下表,如图6-1.Product表用于存储商品的字符类信息,ProductWebInfo用于存储商品的图片,两张表通过SKU关联.现在你想把两张表的信息整合到一个实 ...
- 高性能 TCP/UDP/HTTP 通信框架 HP-Socket v4.0.1
HP-Socket 是一套通用的高性能 TCP/UDP/HTTP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP/HTTP 通信系统,提供 C/ ...
- ES6(let 和 const)
一项新技术的出现肯定是为了解决一些问题,那么ES6的出现主要是解决了哪些问题?它的出现给我们带来了什么便利?当它没有出现的时候,某些问题怎么处理?ES6的方法和以前的方法比较又有什么不同呢?根据提出的 ...
- Android MVP 设计模式
1.基本概念 Model : 模型 负责处理数据的加载或者存储,比如从网络或本地数据库获取数据等: View : 视图 负责界面数据的展示,与用户进行交互: Presenter ...
- tuple放入dict中
tuple放入dict中是否可以正常运行 # 将tuple放入dict中 a = ('AI','Kobe','Yao') b = ('AI',['Kobe','Yao']) dict1 = {'a': ...
- Oracle常用函数汇总
在Oracle OCP考试中,相当一部分知识点涉及到对于Oracle常见函数的考查.尽管Oracle官方文档SQL Language Reference中Functions一章内列举了所有Oracle ...
- 常用MySQL图形化管理工具
MySQL的管理维护工具非常多,除了系统自带的命令行管理工具之外,还有许多其他的图形化管理工具,这里我介绍几个经常使用的MySQL图形化管理工具,供大家参考. MySQL是一个非常流行的小型关系型数据 ...