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. Django之form主键

    Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...

  2. 联想ideapad-330C 在Ubuntu18.04 上安装Realtek 8821CE无线网卡驱动

    在新买的联想ideapad-330C笔记本上,安装Ubuntu 18.04后,悲催的发现,没有无线网络,幸好有线还能用,然后网上搜一波,发现不少人遇到这种问题,也有人给出解决方案 参考的链接: Thi ...

  3. 攻防世界WEB高手进阶之blgdel

    CISCN final 打开页面 扫描目录 Robots.txt Config.txt 代码审计 <?php class master { private $path; private $nam ...

  4. linux中/dev/null与2>&1讲解

    首先先来看下几种标识的含义: /dev/null 表示空设备文件 0 表示stdin标准输入 1 表示stdout标准输出 2 表示stderr标准错误 先看/dev/null command > ...

  5. crontab每小时运行一次(转)

    https://blog.csdn.net/liu0808/article/details/80668705 先给出crontab的语法格式 对于网上很多给出的每小时定时任务写法,可以说绝大多数都是错 ...

  6. TCP滑动窗口(发送窗口和接受窗口)

    TCP窗口机制 TCP header中有一个Window Size字段,它其实是指接收端的窗口,即接收窗口.用来告知发送端自己所能接收的数据量,从而达到一部分流控的目的. 其实TCP在整个发送过程中, ...

  7. Redis主从复制之哨兵模式(sentinel)

    介绍:反客为主的自动版,能够后台监控主机是否故障,如果故障了根据投票数自动将从库转换为主库 调整结构:6379带着80.81 自定义的/myredis目录下新建sentinel.conf文件,名字绝不 ...

  8. [HTTP趣谈]origin,referer和host区别

    发起一个ajax请求时,request header里面有三个属性会涉及请求源信息.前端可能用不到这些值,但是,后台业务系统会比较关心它们,场景可能有: 处理跨域请求时,必须判断来源请求方是否合法:  ...

  9. 未能找到 System.Web.Helpers

    This question is a bit old but here's a simple solution - Microsoft seemed to just move this library ...

  10. 编译lua固件NodeMcu 8266

    https://www.cnblogs.com/yangfengwu/p/10547024.html 因为我现在的Wifi的教程是lua语言编写的,但是有些功能需要自己编译lua固件才可以,这篇文章就 ...