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:// ...
随机推荐
- asp.net core 1.1 升级后,操作mysql出错的解决办法。
遇到问题 core的版本从1.0升级到1.1,操作mysql数据库,查询数据时遇到MissingMethodException问题,更新.插入操作没有问题. 如果你也遇到这个问题,请参照以下步骤进行升 ...
- WPF弹出带蒙板的消息框
效果图 思路 拿到父级窗体的内容,放入一个容器里,再在容器里放入一个半透明层.将整个容器赋给父级窗体的内容. 关闭时反向操作. 代码 消息窗弹出时 /// <summary> /// 弹出 ...
- 第三篇 Entity Framework Plus 之 Query Cache
离上一篇博客,快一周,工作太忙,只能利用休息日来写一些跟大家分享,Entity Framework Plus 组件系列文章,之前已经写过两篇 第一篇 Entity Framework Plus 之 A ...
- Debug JDK变量显形
本文面向的朋友 本文主要说明在使用Eclipse Debug JDK时,看不到变量值的解决办法. 如果您看到上面绿色字体表示不敢兴趣,请一定果断back,如果您不爽,请在下面使劲的拍. Debug J ...
- 关于IOS中safari下的select下拉菜单,文字过长不换行的问题
今天遇到下图这种问题,文字过长,显示不全.折腾了老半天,在网上搜了半天也找不到解决方案. 于是问了下同事,同事提到了<optgroup>,这个标签厉害. <optgroup> ...
- 一分钟搞定AlloyTouch图片轮播组件
轮播图也涉及到触摸和触摸反馈,同时,AlloyTouch可以把惯性运动打开或者关闭,并且设置min和max为运动区域,超出会自动回弹. 除了一般的竖向滚动,AlloyTouch也可以支持横向滚动,甚至 ...
- 服务器开启https协议
开启Tomcat https服务 发布企业级应用的时候遇到一个问题,就是IOS7.1之后app的下载地址URL必须是https开头的协议,所以服务器必须支持https协议. 实验环境:Mac OSX ...
- 安装cocoapods遇到两大坑-Ruby版本升级和Podfile的配置
今天安装cocoapods #移除原有ruby源 $ gem sources --remove https://rubygems.org/ #使用可用的淘宝网 $ gem sources -a htt ...
- 【代码笔记】iOS-UILable高度自适应(sizeWithFont)
一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...
- Mac 开发者常用的工具
转载:http://www.oschina.net/news/53946/mac-dev-tools 在写 Mac 程序员的十个武器之前,我决定先讲一个故事,关于 Mac 和爱情的.(你们不是问 Ma ...