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. mysql设计规范和原则

    DB设计流程: 1,需求分析 2,ER设计 3,物理设计 需求分析的最佳实践是头脑风暴,把需求理解透彻.根据公司的现况和未来的发展,与pm一起来讨论. ER(EntiyRelation)设计阶段要确定 ...

  2. Educational Codeforces Round 67 D. Subarray Sorting

    Educational Codeforces Round 67 D. Subarray Sorting 传送门 题意: 给出两个数组\(a,b\),现在可以对\(a\)数组进行任意次排序,问最后能否得 ...

  3. Win10系统如何关闭自动更新?

    现在很多电脑的系统都升级到了win10了,win10已经渐渐普及到每个人的电脑中,但是,win10系统有一个功能特别讨人厌,我自认为挺讨厌这个功能的,它就是“自动更新”功能,你可能会说,自动更新不是挺 ...

  4. selenium入门知识

    自动化测试 重复测试.性能测试.压力测试 快速.可靠.可重复.可程序化.广泛的 自动化测试适合场合 回归测试.更多更频繁的测试.手工测试无法实现的工作.跨平台产品的测试.重复性很强的操作 不适合场合 ...

  5. Spring Cloud Config 知识点

    Spring Cloud Config项目是一个解决分布式系统的配置管理方案.它包含了Client和Server两个部分,server提供配置文件的存储.以接口的形式将配置文件的内容提供出去,clie ...

  6. Buy Fruits-(构造)

    https://ac.nowcoder.com/acm/contest/847/C 在blueland上有 n n个水果店,它们的编号依次为 0,1,2...n−1 0,1,2...n−1.奇妙的是, ...

  7. drf常用方法

    1.认证 2.权限 3.序列化 4.分页 5.限流

  8. node.js封装数据库增删改查

    数据库增删改查的封装 小编不容易 const sql = { insert: function (Collection, insertData) { return new Promise((resol ...

  9. Android Studio软件技术基础 —Android项目描述---1-类的概念-android studio 组件属性-+标志-Android Studio 连接真机不识别其他途径

    学习android对我来说,就是兴趣,所以我以自己的兴趣写出的文章,希望各位多多支持!多多点赞,评论讨论加关注. 最近有点忙碌,对于我来说,学习Android开发,是对于我的考验,最近一位大佬发给我一 ...

  10. LCA的多种求法(超详细!!!)

    倍增求LCA (1)树上倍增法 预处理 设f[x,k]表示x的2^k辈祖先,即从x向根节点走2^k步到达的节点.特别地,若该节点不存在,则令f[x,k]=0.f[x,0]就是x的父节点.可以得出f[x ...