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——文件操作
一.文件的打开和关闭 1.常用的打开关闭语句 f=open("yesterday","r",encoding="utf-8") #打开文件 ...
- 获取数值型数组的最大值和最小值,使用遍历获取每一个值,然后记录最大值和最小值的方式。(数组遍历嵌套if判断语句)
package com.Summer_0420.cn; /** * @author Summer * .获取数值型数组的最大值.最小值 * 方法:遍历获取每一个值,记录最大值: * 方法:遍历获取每一 ...
- Egg入门学习(二)---理解service作用
在上一篇文章 Egg入门学习一 中,我们简单的了解了Egg是什么东西,且能做什么,这篇文章我们首先来看看官网对Egg的整个框架的约定如下,及约定对应的目录是做什么的,来有个简单的理解,注意:我也是按照 ...
- HBase篇(3)-架构详解
[每日五分钟搞定大数据]系列,HBase第三篇 聊完场景和数据模型我们来说下HBase的架构,在网上找了张比较清晰的图,我觉得这张图能说明很多问题,那这一篇我们就重点来解析下这张图 角色与职责 先介绍 ...
- github/gitlab同时管理多个ssh key
之前一直用github,但是github有一个不好的地方,要是创建私有的项目的话需要付费,而gitlab上则可以免费创建管理私有的项目.由于最近想把自己论文的一些东西整理一下,很多东西还是不方便公开, ...
- Python 内置库 sys用法
sys模块功能众多,这边先学习几个常用的方法sys常见函数列表① sys.argv: 实现从程序外部向程序传递参数.其实sys.argv[]就是一个列表,里面的项为用户输入的参数,但是sys.argv ...
- 安装配置JDK和Eclipse的步骤
导读 作为Java程序员,需要在Linux系统上安装Eclipse,很多人不知要如何安装,在安装Eclipse前,还需安装JDK,Linux下如何安装JDK和Eclipse呢?下面跟朋友们介绍下Lin ...
- 利用tushare进行对兴业银行股价的爬取,并使用numpy进行分析
import sysimport tushare as tsimport numpy as npdata=ts.get_h_data('601066')print(data)#读出兴业银行7列数据da ...
- Mysql数据库中的日期相关操作
1.获取当前时间的日期 select now();----------------------------------如:2008-12-29 16:25:46 select curdate();-- ...
- yield from
一.yield 关于yield详细可参考我这篇文章 下面是一个带yield的生成器: def gen_yield(): while True: recv = yield do something wi ...