MyBatis学习:http://www.mybatis.org/mybatis-3/zh/index.html

大对象InsuranceDetailsVO:

  1. com.quicksure.mobile.entity.InsuranceDetailsVO
  2.  
  3. public class InsuranceDetailsVO {
  4. private String orderno;
  5. @Resource
  6. private Baseinfor baseinfor;
  7. @Resource
  8. private Coverageinfor coverageinfor;
  9.  
  10. private List<Coverageinfor> coverageinfors; //险种的集合
  11.  
  12. ........其它无关实体类和getset方法省略
  13. }

实体类Baseinfor:

  1. com.quicksure.mobile.entity.Baseinfor
  2.  
  3. public class Baseinfor {
  4. private String orderno;// 订单号
  5.  
  6. ......一些基本的字段和getset方法
  7. }

对应的mapper:

  1. 联合查询,一对一
    <mapper namespace="com.quicksure.mobile.dao.VelicheBatchCheckMapper">
  2. <resultMap id="queryBatchPolicy" type="com.quicksure.mobile.entity.InsuranceDetailsVO">
  3. <id column="orderNo" jdbcType="VARCHAR" property="orderno" />
  4. <collection property="baseinfor" ofType="com.quicksure.mobile.entity.Baseinfor" resultMap="baseinforResult"></collection>
  5. </resultMap>

  6. 联合查询,一对多
  7. <resultMap id="queryBatchPolicy1" type="com.quicksure.mobile.entity.InsuranceDetailsVO">
  8. <id column="orderNo" jdbcType="VARCHAR" property="orderno" />
  9. <collection property="baseinfor" ofType="com.quicksure.mobile.entity.Baseinfor" resultMap="baseinforResult"></collection>
  10. <collection property="coverageinfors" ofType="com.quicksure.mobile.entity.Coverageinfor" resultMap="coverageinforResult"></collection>
  11. </resultMap>
  12. <resultMap id="baseinforResult" type="com.quicksure.mobile.entity.Baseinfor">
      ......基本字段映射
  13. </resultMap>
  14.  
  15. <resultMap id="coverageinforResult" type="com.quicksure.mobile.entity.Coverageinfor">
      ......基本字段映射
  16. </resultMap>
  17.  
  18. <!-- CSR导出excel时查询对应的数据 -->
  19. <select id="CSRExportExcel" parameterType="java.util.Map" resultMap="queryBatchPolicy1">
  20. select
  21. baseinfor.orderNo,baseinfor.syapplicationNo,baseinfor.jqapplicationNo,baseinfor.sypolicyNo,baseinfor.jqpolicyNo,
  22. baseinfor.deptAddress,vhinfor.drvOwner,vhinfor.lcnNo,baseinfor.sypolicyStartDate,baseinfor.jqpolicyStartDate,
  23. baseinfor.orderstate,baseinfor.syPremium,baseinfor.jqPremium,baseinfor.taxPremium,baseinfor.totalPremium,
  24. baseinfor.updateTime,baseinfor.paymentMethod,baseinfor.jqpolicyNo,baseinfor.sypolicyNo,baseinfor.createTime,
  25. coverage.*
  26. from
  27. ludimb_baseinfor baseinfor
  28. LEFT JOIN ludimb_vhlinfor vhinfor on baseinfor.vhlinforId = vhinfor.vhiinforId
  29. LEFT JOIN ludimb_coverageinfor coverage on baseinfor.orderNo = coverage.baseinforOrderNo
  30. where 1=1
  31. <if test="deptcode!=null and deptcode!='' and deptcode!=1">
  32. and baseinfor.deptNo=#{deptcode}
  33. </if>
  34. <if test="orderNo!=null and orderNo!=''">
  35. and baseinfor.orderNo=#{orderNo}
  36. </if>
  37. <if test="drvowner!=null and drvowner!=''">
  38. and vhinfor.drvOwner=#{drvowner}
  39. </if>
  40. <if test="lcnNo!=null and lcnNo!=''">
  41. and vhinfor.lcnNo=#{lcnNo}
  42. </if>
  43. <choose>
  44. <when test="orderstate==1">
  45. and baseinfor.orderstate in (30,40)
  46. </when>
  47. <when test="orderstate==2">
  48. and baseinfor.orderstate in (50,60,70)
  49. </when>
  50. <when test="orderstate==3">
  51. and baseinfor.orderstate in (10,20)
  52. </when>
  53. <when test="orderstate==4">
  54. and baseinfor.orderstate = 80
  55. </when>
  56. <otherwise>
  57. </otherwise>
  58. </choose>
  59. <if test="createStartTime!=null and createStartTime!=''">
  60. <![CDATA[ and baseinfor.createTime >= #{createStartTime} ]]>
  61. </if>
  62. <if test="createEndTime!=null and createEndTime!=''">
  63. <![CDATA[ and baseinfor.createTime <= #{createEndTime} ]]>
  64. </if>
  65. </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. asp.net core 1.1 升级后,操作mysql出错的解决办法。

    遇到问题 core的版本从1.0升级到1.1,操作mysql数据库,查询数据时遇到MissingMethodException问题,更新.插入操作没有问题. 如果你也遇到这个问题,请参照以下步骤进行升 ...

  2. WPF弹出带蒙板的消息框

    效果图 思路 拿到父级窗体的内容,放入一个容器里,再在容器里放入一个半透明层.将整个容器赋给父级窗体的内容. 关闭时反向操作. 代码 消息窗弹出时 /// <summary> /// 弹出 ...

  3. 第三篇 Entity Framework Plus 之 Query Cache

    离上一篇博客,快一周,工作太忙,只能利用休息日来写一些跟大家分享,Entity Framework Plus 组件系列文章,之前已经写过两篇 第一篇 Entity Framework Plus 之 A ...

  4. Debug JDK变量显形

    本文面向的朋友 本文主要说明在使用Eclipse Debug JDK时,看不到变量值的解决办法. 如果您看到上面绿色字体表示不敢兴趣,请一定果断back,如果您不爽,请在下面使劲的拍. Debug J ...

  5. 关于IOS中safari下的select下拉菜单,文字过长不换行的问题

    今天遇到下图这种问题,文字过长,显示不全.折腾了老半天,在网上搜了半天也找不到解决方案. 于是问了下同事,同事提到了<optgroup>,这个标签厉害. <optgroup> ...

  6. 一分钟搞定AlloyTouch图片轮播组件

    轮播图也涉及到触摸和触摸反馈,同时,AlloyTouch可以把惯性运动打开或者关闭,并且设置min和max为运动区域,超出会自动回弹. 除了一般的竖向滚动,AlloyTouch也可以支持横向滚动,甚至 ...

  7. 服务器开启https协议

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

  8. 安装cocoapods遇到两大坑-Ruby版本升级和Podfile的配置

    今天安装cocoapods #移除原有ruby源 $ gem sources --remove https://rubygems.org/ #使用可用的淘宝网 $ gem sources -a htt ...

  9. 【代码笔记】iOS-UILable高度自适应(sizeWithFont)

    一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...

  10. Mac 开发者常用的工具

    转载:http://www.oschina.net/news/53946/mac-dev-tools 在写 Mac 程序员的十个武器之前,我决定先讲一个故事,关于 Mac 和爱情的.(你们不是问 Ma ...