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 ...
随机推荐
- java 定时任务多线程处理
@Configuration@EnableSchedulingpublic class ScheduleConfig implements SchedulingConfigurer, AsyncCon ...
- spring boot启动报错
Exception encountered during context initialization - cancelling refresh attempt: org.springframewor ...
- (5)HomeAssistant 增加设备
将设备添加到Home Assistant https://www.home-assistant.io/docs/configuration/devices/ configuration.yaml文件 ...
- SQL开发规范
一.SQL代码规范: 1.头部 --************************************************************************** --所属主题: ...
- 【重磅干货整理】机器学习(Machine Learning)与深度学习(Deep Learning)资料汇总
[重磅干货整理]机器学习(Machine Learning)与深度学习(Deep Learning)资料汇总 .
- 波音,自动驾驶bug未修复,致346人丧生!5个月内两次坠毁!其中,包括8名中国公民
一,波音737 MAX再次坠毁 继2018年10月29日,印尼波音737MAX飞机坠入爪哇海,导致178名乘客不幸遇难后,时隔不足5月,上周日,埃塞俄比亚航空公司一架波音737MAX客机在飞往肯尼亚途 ...
- Django Rest framework基础使用之Request/Response
1.Request restframework提供了一个Request对象(rest_framework.request.Request) Request对象继承了Django默认的HttpReque ...
- Python-sys模块-61
sys 模块:和Python解释器打交道的模块 sys模块是与python解释器交互的一个接口 sys.argv 命令行参数List,第一个元素是程序本身路径 sys.exit(n) 退出程序,正常退 ...
- Spring Data Elasticsearch 和 x-pack 用户名/密码验证连接
Elasticsearch Java API 客户端连接 一个是TransportClient,一个是NodeClient,还有一个XPackTransportClient TransportClie ...
- Git更新本地仓库
1.查看远程仓库git remote -v2.从远程获取最新版本到本地git fetch origin master:temp3.比较本地的仓库与远程仓库的区别git diff temp4.合并tem ...