mybatis的collection的使用

现象:
mybatis的collection的使用

方法:
1:主查询返回的map:
这里写图片描述
2:子查询返回对象的map
这里写图片描述
3:主查询sql语句
这里写图片描述
4:子查询语句
这里写图片描述
5:使用主查询返回的结果作为子查询的条件字段去子查询查询
这里写图片描述
6:接收数据对象,主对象中包含子对象中的集合
这里写图片描述

代码样例:

<resultMap type="com.oig.bean.SumDocuments" id="sumDocument">
        <result property="cid" column="cid"/>
        <result property="subscribedate" column="subscribedate"/>
        <result property="contractno" column="contractno"/>
        <result property="originplace" column="originplace"/>
        <result property="gnamedesc2" column="gnamedesc2"/>
        <result property="header" column="header"/>
        <result property="factoryno" column="factoryno"/>
        <result property="linkccode" column="linkccode"/>
        <result property="ccodetrust" column="ccodetrust"/>
        <result property="cname" column="cname"/>
        <result property="wname" column="wname"/>
        <result property="cpname" column="cpname"/>
        <result property="ordicode" column="ordicode"/>
        <collection property="list" column="{cid=cid,ordicode=ordicode}" javaType="ArrayList"  ofType="com.oig.bean.Documents" select="findDocumentByCid"/>
    </resultMap>
    <resultMap type="com.oig.bean.Documents" id="DocumentsMap">
        <result property="subscribedate" column="subscribedate"/>
                <result property="contractno" column="contractno"/>
                <result property="originplace" column="originplace"/>
                <result property="gnamedesc2" column="gnamedesc2"/>
                <result property="header" column="header"/>
                <result property="factoryno" column="factoryno"/>
                <result property="linkccode" column="linkccode"/>
                <result property="ccodetrust" column="ccodetrust"/>
                <result property="cname" column="cname"/>
                <result property="wname" column="wname"/>
                <result property="cpname" column="cpname"/>
                <result property="ordicode" column="ordicode"/>
    </resultMap>
    <select id="findsumDocumentBySql" parameterType="java.lang.String" resultMap="sumDocument">
        select 
            SUBSTRING(convert(varchar(100),max(subscribedate),20),1,10) as subscribedate,
            cid as cid,
            MAX(contractno) as contractno,
            MAX(originplace) as originplace,
            MAX(gnamedesc2) as gnamedesc2,
            MAX(header) as header,
            MAX(factoryno) as factoryno,
            MAX(linkccode) as linkccode,
            MAX(cname) as cname,
            MAX(wname) as wname,
            ordicode as ordicode,
            MAX(ccodetrust) as ccodetrust,
            MAX(cpname) as cpname
        from v_documents where 1=1 ${else_if} group by cid,ordicode
    </select>
    <select id="findDocumentByCid" parameterType="java.util.Map" resultMap="DocumentsMap">
        select * from v_documents where 1=1
         <choose>
        <when test="cid==null">
            and cid is null
        </when>
        <otherwise>
            and cid=#{cid}
        </otherwise>
        </choose>
         and ordicode=#{ordicode}
    </select>
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值