Mybatis之collection嵌套查询mapper文件写法
mapper.xml写法举例
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="maserati.dao.meta.list.ListSchemaMapper">
<resultMap id="BaseResultMap" type="maserati.dao.meta.list.entity.ListSchemaEntity">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="mod_name" property="modName" jdbcType="VARCHAR"/>
<result column="prop_name" property="propName" jdbcType="VARCHAR"/>
<result column="prop_desc" property="propDesc" jdbcType="VARCHAR"/>
<result column="del_flag" property="delFlag" jdbcType="BIT"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
</resultMap> <resultMap id="ListMeta" type="maserati.dao.meta.list.entity.ListMeta">
<result column="mod_name" property="modName" jdbcType="VARCHAR"/>
<result column="mod_desc" property="modTitle" jdbcType="VARCHAR"/>
<collection property="tHeads" ofType="maserati.dao.meta.list.entity.PropMeta"
select="selectTableHeads" column="mod_name" javaType="ArrayList"/>
</resultMap>
<resultMap id="TableHead" type="maserati.dao.meta.list.entity.PropMeta">
<result property="propName" column="prop_name" jdbcType="VARCHAR"/>
<result property="propDesc" column="prop_desc" jdbcType="VARCHAR"/>
<result property="propType" column="prop_type" jdbcType="VARCHAR"/>
</resultMap> <sql id="Base_Column_List">
id, mod_name, prop_name, prop_desc, del_flag, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from t_list_schema
where id = #{id,jdbcType=INTEGER}
</select> <select id="selectAllProdListMeta" resultMap="ListMeta">
select
distinct mod_name,mod_desc
from t_list_schema where mod_name in ('loan','credit_card','other_prod') and del_flag = 0
</select> <select id="selectTableHeads" resultMap="TableHead" parameterType="java.lang.String">
select prop_name,prop_desc,prop_type
from t_list_schema where mod_name='${value}' and del_flag = 0 order by sort_index
</select> <select id="selectPropNameByModName" resultType="java.lang.String" parameterType="java.lang.String">
select prop_name from t_list_schema where mod_name=#{value} and del_flag=0
order by sort_index
</select> <select id="selectTableHeadsByModName" resultMap="TableHead" >
select prop_name,prop_desc,prop_type from t_list_schema where mod_name=#{value} and del_flag=0
order by sort_index
</select>
</mapper>
Mybatis之collection嵌套查询mapper文件写法的更多相关文章
- Mybatis框架的模糊查询(多种写法)、删除、添加(四)
学习Mybatis这么多天,那么我给大家分享一下我的学习成果.从最基础的开始配置. 一.创建一个web项目,看一下项目架构 二.说道项目就会想到需要什么jar 三.就是准备大配置链接Orcl数据库 & ...
- 【坑】Mybatis 多次逆向工程生成mapper文件
在使用 mybatis 逆向工程的时候,多次逆向工程生成的文件,是不会产生覆盖的,而是追加: 假如,你第一次逆向,发生数据库的某个字段类型错了,修改以后再次逆向,那么得到的 mapper文件,将是 2 ...
- Mybatis源码分析之Mapper文件解析
感觉CSDN对markdown的支持不够友好,总是伴随各种问题,很恼火! xxMapper.xml的解析主要由XMLMapperBuilder类完成,parse方法来完成解析: public void ...
- mybatis中collection子查询注入参数为null
具体实现参照网上,但是可能遇到注入参数为null的情况,经过查阅及自己测试记录一下: 子查询的参数中,有<if test="">之类,需要指定别名,通过 http:// ...
- mybatis两种嵌套查询方式
1,推荐用第一种 <select id="getTeacher2" resultMap="TeacherStudent"> select s.id ...
- mybatis 关联查询和嵌套查询的简单示例
两个表: Customer 顾客表 create table if not exists customer( customer_id int primary key auto_increment, f ...
- mybatis 嵌套查询与懒加载
懒加载:对于页面有很多静态资源的情况下(比如网商购物页面),为了节省用户流量和提高页面性能,可以在用户浏览到当前资源的时候,再对资源进行请求和加载. fetchType="lazy" ...
- mybatis的嵌套查询与嵌套结果查询的不同
原文:https://blog.csdn.net/qq_39706071/article/details/85156840 实体类: 嵌套查询mapper方法:嵌套查询的弊端:即嵌套查询的N+1问题尽 ...
- Mybatis之collection与association标签
collection与association标签的功能就是为了解决查询条件映射到一个类或一个集合上,适用于对于多对一,一对多的映射结果,现在我们就探究其具体使用吧. 环境搭建: 数据库搭建 CREAT ...
随机推荐
- Python中关于if __name__=='__main__'的问题
先举一个简单的例子: 这里有两个.py的文件,a.py和b.py a.py内容为: b.py的内容为: 当执行b.py时结果为: 也就是将a.py文件里的内容执行一边,b.py里的内容执行一边,这显然 ...
- ActiveMQ发布订阅模式 转发 https://www.cnblogs.com/madyina/p/4127144.html
ActiveMQ的另一种模式就SUB/HUB即发布订阅模式,是SUB/hub就是一拖N的USB分线器的意思.意思就是一个来源分到N个出口.还是上节的例子,当一个订单产生后,后台N个系统需要联动,但有一 ...
- oracle 11G direct path read 很美也很伤人
direct path read在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读 ...
- Linux 分卷压缩
例如,要将大文件夹 PYNQ 分卷压缩成 1G 的单元大小,如下命令(类似的可以指定 tar 的参数为 czf 而生产 .tar.gz 格式的压缩包:可以指定分卷大小例如 500M 等),压缩完成后, ...
- wxWidgets 在 Linux 下开发环境配置
本文基于 CodeBlocks (16.0.1) 和 wxWidgets (3.0.2) 搭建 Linux 下 GUI 开发环境. 1. 安装 CodeBlocks Ubuntu 默认的源当前 Cod ...
- AI Haar特征
Haar特征,也叫矩形特征,有四种特征(模板):边缘特征.线性特征.中心特征.对角线特征.每种模板都包含黑白两种区域. 模板的特征值=白色区域的像素和-黑色区域的像素和,反映的是图像的灰度变化情况. ...
- Java学习之路- SQL注入
用户名: __________ 密码:——————— 假如没有使用预处理的Statement 对象 拼接字符串查数据库的话,易收到sql注入攻击: 例如说 : mysql 中 #代表的是单行注释 ...
- 朱晔的互联网架构实践心得S1E10:数据的权衡和折腾【系列完】
朱晔的互联网架构实践心得S1E10:数据的权衡和折腾[系列完] [下载本文PDF进行阅读] 本文站在数据的维度谈一下在架构设计中的一些方案对数据的权衡以及数据流转过程中的折腾这两个事情.最后进行系列文 ...
- [书籍]用UWP复习《C#并发编程经典实例》
1. 简介 C#并发编程经典实例 是一本关于使用C#进行并发编程的入门参考书,使用"问题-解决方案-讨论"的模式讲解了以下这些概念: 面向异步编程的async和await 使用TP ...
- Jenkins - Extended E-mail配置教程
前言: 在Jenkins的使用中邮件提醒是一个常用功能,Extended E-mail Notification是一个功能更为齐全,使用也更为复杂的插件,本文即将为大家详细讲解如何配置相关内容,感兴趣 ...