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. ubuntu用samba来实现和虚拟机的文件共享

    1.安装samba sudo apt install -y samba sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak 2.创建文件夹并修改权限 ...

  2. Hexo 文章图片添加水印,不用云处理

    由于网上找到的都是借用第三方云处理添加水印,但是我不太想用,所以自己开发了一个插件 Hexo 图片添加水印Github地址 目前插件可以直接在 hexo 官网上搜索到 下面内容都是在 Github 上 ...

  3. qt5.12 解决显示中文乱码问题

    在菜单栏   文件->选项,找到文本编辑器 文件编码设置如图 在cpp文件中加入 #pragma execution_character_set("utf-8") 之后就可以 ...

  4. 如何让自己的Dev C++用上C++11标准

    首先确保Dev C++版本是最新的5.11版 其实用C++11标准的语法去运行还是会出现结果的,最多warning一下 但完美主义者是不允许这样的 我们可以点击菜单栏的“工具”->“编译选项”进 ...

  5. xtrabackup 使用

    创建具有完全备份所需的最小权限的数据库用户的SQL示例如下 mysql> CREATE USER 'bkpuser'@'%' IDENTIFIED BY 's3cret';mysql> G ...

  6. python 验证码识别示例(四) 简单验证码识别

    今天介绍一个简单验证的识别. 主要是标准的格式,没有扭曲和变现.就用 pytesseract 去识别一下. 验证码地址:http://wsxf.mca.gov.cn/zfp/Random.cmd?d= ...

  7. Object类.时间日期类.System类.Stringbuilder类.包装类

    Object类 java.lang.Object类是java语言中的根类,即所有类的父类.它中描述的所有方法都可以使用.在对象实例化的时候,最终找的父类就是Object. 如果一个类没有特别指定父类, ...

  8. utf8mb4版本设置django

    'OPTIONS':{ 'init_command':"SET sql_mode='STRICT_TRANS_TABLES'", 'charset':'utf8mb4',

  9. MySQL 快速删除大量数据

    千万级数据量 方案1. 直接使用delete 因delete执行速度与索引量成正比,若表中索引量较多,使用delete会耗费数小时甚至数天的时间   方案2. (1)创建临时表,表结构与原表结构相同 ...

  10. Helm 安装Nginx Ingress

    为了便于将集群中的服务暴露到集群外部,需要使用Ingress.接下来使用Helm将Nginx Ingress部署到Kubernetes上. Nginx Ingress Controller被部署在Ku ...