networkResource的 resultMap

<resultMap id="NetworkResultMap"  type="com.chinamobile.epic.zebra.model.NetworkResource">
<id column="id" property="id" jdbcType="CHAR" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="admin" property="admin" jdbcType="BIT" />
<result column="shared" property="shared" jdbcType="BIT" />
<result column="type" property="type" jdbcType="VARCHAR" />
<result column="organization_id" property="organizationId"
jdbcType="CHAR" />
<result column="external" property="external" jdbcType="BIT" />
<result column="segmentation_id" property="segmentationId"
jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="VARCHAR" />
<result column="physical_name" property="physicalName"
jdbcType="VARCHAR" />
<result column="user_id" property="userId" jdbcType="CHAR" />
<result column="pool_id" property="poolId" jdbcType="CHAR" />
<result column="order_id" property="orderId" jdbcType="CHAR" />
<result column="deleted" property="deleted" jdbcType="BIT" />
<result column="business_id" jdbcType="CHAR" property="businessId" />
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
<result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP" />
<result column="region_name" property="regionName" jdbcType="VARCHAR" />
<result column="variety" property="variety" jdbcType="INTEGER" />
<result column="domain" property="domain" jdbcType="CHAR" />
<result column="d_name" property="domainName" jdbcType="CHAR" />
<result column="vpc_id" property="vpcId" jdbcType="CHAR" />
<result column="is_classic" property="isClassic" jdbcType="TINYINT" />
<result column="mtu" property="mtu" jdbcType="VARCHAR" />
<result column="vlan_transparent" property="vlanTransparent"
jdbcType="BIT" />
<result column="qos_policy_id" property="qosPolicyId" jdbcType="CHAR" />
<result column="ip_version" property="ipVersion" jdbcType="INTEGER" />
<result column="description" property="description" jdbcType="VARCHAR" />
<collection property="labels"
ofType="com.chinamobile.epic.zebra.model.Label">
<id column="l_id" property="id" jdbcType="CHAR" />
<result column="l_name" property="name" jdbcType="VARCHAR" />
</collection>
</resultMap>

子网的resultMap

<resultMap id="SubnetResultMap"
type="com.chinamobile.epic.zebra.model.SubnetResource">
<id column="s_id" property="id" jdbcType="CHAR" />
<result column="s_name" property="name" jdbcType="VARCHAR" />
<result column="s_enable_dhcp" property="enableDhcp" jdbcType="BIT" />
<result column="s_network_id" property="networkId" jdbcType="CHAR" />
<result column="s_organization_id" property="organizationId"
jdbcType="CHAR" />
<result column="s_dns_names" property="dnsNames" jdbcType="VARCHAR" />
<result column="s_allocation_pools" property="allocationPools"
jdbcType="VARCHAR" />
<result column="s_gateway" property="gateway" jdbcType="VARCHAR" />
<result column="s_ip_version" property="ipVersion" jdbcType="INTEGER" />
<result column="s_cidr" property="cidr" jdbcType="VARCHAR" />
<result column="s_user_id" property="userId" jdbcType="CHAR" />
<result column="s_pool_id" property="poolId" jdbcType="CHAR" />
<result column="s_order_id" property="orderId" jdbcType="CHAR" />
<result column="s_deleted" property="deleted" jdbcType="BIT" />
<result column="s_created_at" property="createdAt" jdbcType="TIMESTAMP" />
<result column="s_updated_at" property="updatedAt" jdbcType="TIMESTAMP" />
<result column="s_business_id" property="businessId" jdbcType="CHAR" />
<result column="s_region_name" property="regionName" jdbcType="VARCHAR" />
<result column="s_ip_count" property="ipCount" jdbcType="INTEGER" />
<result column="s_ipv6_address_mode" property="ipv6AddressMode"
jdbcType="VARCHAR" />
<result column="s_ipv6_ra_mode" property="ipv6RaMode" jdbcType="VARCHAR" />
</resultMap>

网络与子网的1:N关系的resultMap

	<resultMap id="DetailResultMap"	type="com.chinamobile.epic.zebra.model.NetworkResource" extends="NetworkResultMap">
<collection property="subnetResources" column="id" resultMap="SubnetResultMap" />
</resultMap>

sql查询

<sql id="network_Column_List">
n.id, n.name, n.admin, n.shared, n.type, n.organization_id,
n.external,
n.segmentation_id, n.deleted,
n.status, n.physical_name,
n.user_id, n.pool_id, n.order_id,
n.business_id,
n.created_at, n.updated_at, n.region_name, n.variety, n.domain,
n.vpc_id, n.is_classic,
n.mtu, n.vlan_transparent,
n.qos_policy_id,n.ip_version,n.description
</sql> <sql id="subnet_Column_List">
s.id s_id, s.name s_name, s.enable_dhcp s_enable_dhcp, s.dns_names
s_dns_names, s.allocation_pools s_allocation_pools, s.gateway
s_gateway, s.ip_version s_ip_version, TRIM(s.cidr) s_cidr
</sql>

具体的sql

<select id="selectWith" resultMap="DetailResultMap"
parameterType="java.lang.String">
select
<include refid="network_Column_List" />
,
<include refid="subnet_Column_List" />
,
<include refid="Base_Column_Label" />
from networks n
left join subnets s on n.id = s.network_id
left join
crab.organizations o on o.id = n.organization_id
left join
label_relations lr ON lr.resource_id = n.id AND lr.deleted = false
left join labels l ON l.id = lr.label_id AND l.deleted = false
<where>
<if test="poolId != null ">
n.pool_id = #{poolId, jdbcType=CHAR}
</if>
<if test="orgDomainId != null ">
AND o.domain_id = #{orgDomainId, jdbcType=CHAR}
</if>
<if test="ipVersion != null">
AND s.ip_version = #{ipVersion, jdbcType=INTEGER}
</if>
<if test="type != null ">
AND n.type = #{type, jdbcType=VARCHAR}
</if>
<if test="domainId != null ">
AND n.domain = #{domainId, jdbcType=CHAR}
</if>
<if test="organizationId != null ">
AND (n.organization_id = #{organizationId, jdbcType=CHAR}
or n.organization_id is null)
</if>
<if test="external != null ">
AND n.external = #{external, jdbcType=BIT}
</if>
<if test="shared != null ">
AND n.shared = #{shared, jdbcType=BIT}
</if>
<if test="businessId != null">
AND (n.business_id=#{businessId,jdbcType=CHAR} or
n.business_id is null)
</if>
<if test="variety != null ">
AND n.variety = #{variety, jdbcType=INTEGER}
</if>
<if test="labelId != null">
AND l.id = #{labelId,jdbcType=CHAR}
</if>
AND n.deleted = false
</where>
</select>

【mybatis】子查询的更多相关文章

  1. MyBatis子查询

    一.父查询BaseChildResultMap: <?xml version="1.0" encoding="UTF-8" ?> <!DOCT ...

  2. Mybatis 子查询

    在查询数据库时,需要以查询结果为查询条件进行关联查询. 在mybatis中通过association标签和collection标签实现子查询. 1. collection(集合)和associatio ...

  3. coding++:mybatis 嵌套查询子查询column传多个参数描述

    mybatis 嵌套查询子查询column传多个参数如下: 2.代码示例 备注:注意,相同颜色的单词都是有关联的 <resultMap id="blogResult" typ ...

  4. Mybatis 一对多延迟加载,并且子查询中与主表字段不对应 (19)

    Mybatis  一对多延迟加载,并且子查询中与主表字段不对应应用说明. 实现一对多关联(懒加载),一个教研组对应多个教师,既:教师的教研编号与教研组的教研编号关联,并且教师关联教研组外键与教研组编号 ...

  5. mybatis中collection子查询注入参数为null

    具体实现参照网上,但是可能遇到注入参数为null的情况,经过查阅及自己测试记录一下: 子查询的参数中,有<if test="">之类,需要指定别名,通过 http:// ...

  6. MyBatis关联查询分页

    背景:单表好说,假如是MySQL的话,直接limit就行了. 对于多对多或者一对多的情况,假如分页的对象不是所有结果集,而是对一边分页,那么可以采用子查询分页,再与另外一张表关联查询,比如: sele ...

  7. mybatis分页查询的万能模板

    分页查询项目里太多了,而这种分页查询,在mybatis里面的配置几乎一模一样,今天就整理一个比较好和实用的模板,供以后直接Ctrl+C <select id="queryMember& ...

  8. mybatis分页查询,SqlServer 2008 查询速度很慢

    一个业务场景,需要进行union查询: 查询速度非常慢,大概要37秒: 直接复制sql在数据库客户端执行,速度很快,由此可知是mybatis的原因,在网上搜索,可以配置fetchSize=" ...

  9. MyBatis高级查询 一对一映射

    drop database if exists simple; create database simple; use simple; drop table if exists sys_user; c ...

  10. MyBatis 关联查询的实现:一对多

    有2个实体:用户.订单,一个用户可以拥有多个订单,同时这多个订单属于一个用户,即一对多. user_tb: order_tb: 在“多”的一方(order)添加“一”的一方(user)的主键(user ...

随机推荐

  1. 微服务框架---搭建 go-micro环境

    1.安装micro 需要使用GO1.11以上版本 #linux 下 export GO111MODULE=on export GOPROXY=https://goproxy.io # windows下 ...

  2. RHEL6+GFS2+MYSQL高可用

    RHCS集群安装部署 组件介绍: luci: luci是一个基于web的,用来管理和配置RHCS集群,通过luci可以轻松的搭建一个功能强大的集群系统,节点主机可以使用ricci来和luci 管理段进 ...

  3. 详解CentOS6.7部署Tomcat及主配置文件

    Java程序实现部署及应用 POSIX :可移植操作系统,编程操作系统接口规范,实现跨平台编译运行. API:应用程序编程接口 ABI:应用程序二进制接口 描述了应用程序和操作系统之间,一个应用和它的 ...

  4. Word 页码设置教程:如何删除封面和目录的目录?

    我们常写的报告大都由封面.目录.正文和附录组成,但是页码通常是从正文开始的,所以下面介绍如何从指定页面开始设置页码. 在介绍之前需要了解一下分隔符的作用.分隔符大体分成分页符和分节符. 分页符细分的几 ...

  5. tf学习

    常用命令: 1.显示tf框架: rosrun tf view_frames evince frames.pd tf变换,定义不同坐标系之间的平移与旋转变换关系. 参考文献: tf教程 古月居博客

  6. 201671010418 刘佳 实验十四 团队项目评审&课程学习总结

    项目 内容 这个作业属于哪个课程 软件工程 这个作业的要求在哪里 实验十四 团队项目评审&课程学习总结 作业学习目标 (1)掌握软件项目评审会流程: (2)反思总结课程学习内容. Start: ...

  7. 项目Beta冲刺随笔集合

    班级:软件工程1916|W 作业:项目Beta冲刺 团队名称:SkyReach 目标:完成项目Beta版本 项目Github地址 评审表 团队博客汇总 队员学号 队员姓名 个人博客地址 备注 2216 ...

  8. AppDomain.Unload_MarshalByRefObject

    internal string GetClassInfo(string assemblyName, string className, string strField) { string ret = ...

  9. CustomHTTPProtocol

    http://blog.csdn.net/jingcheng345413/article/details/54967739 一.概念 NSURLProtocol也是苹果众多黑魔法中的一种,使用它可以轻 ...

  10. What is the difference between Reactjs and Rxjs?--React is the V (View) in MVC (Model/View/Controller).

    This is really different, React is view library; and Rxjs is reactive programming library for javasc ...