mybaits两种关联查询
来源:互联网 发布:白板软件下载 编辑:程序博客网 时间:2024/06/17 16:39
关联查询分两种:
1,用一个总的sql搞定
这种关联体现在collect用的是标签,sql中查询主实体,被关联实体(由于在一个sql中,注意两个实体(查询结果集)中字段名不能一样
,一样的化会在用pagehelper等自动装配的语句出问题(未明确定义列),还有就是如果id一样会导致多方只查到一个)
此方法看上篇文章,关联查询同名字段问题
2,用子查询,collection中用的是sql子查询代替标签,另外一个总的查询只查询主体,他们的关联体现在子查询的sql中
1,连接,2条件列压入
<resultMap id="BaseResultMapr" type="com.esteel.system.bean.OpmRole" >
<!--
WARNING - @mbggenerated
-->
<id column="ID" property="id" jdbcType="VARCHAR" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="ORGANID" property="organid" jdbcType="VARCHAR" />
<result column="VALID" property="valid" jdbcType="VARCHAR" />
<result column="MEMO" property="memo" jdbcType="VARCHAR" />
<result column="LEVEL1" property="level1" jdbcType="DECIMAL" />
<result column="SUBSYSTEM" property="subsystem" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="BaseResultMapVo" type="com.esteel.system.beanVo.OpmUserVo" >
<id column="ID" property="id" jdbcType="VARCHAR" />
<result column="CODE" property="code" jdbcType="VARCHAR" />
<result column="PASSWORD" property="password" jdbcType="VARCHAR" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="TELEPHONE" property="telephone" jdbcType="VARCHAR" />
<result column="EMAIL" property="email" jdbcType="VARCHAR" />
<result column="ORGANID" property="organid" jdbcType="VARCHAR" />
<result column="VALID" property="valid" jdbcType="VARCHAR" />
<result column="MEMO" property="memo" jdbcType="VARCHAR" />
<result column="LEVEL1" property="level1" jdbcType="DECIMAL" />
<result column="LAST_LOGIN_DATE" property="lastLoginDate" jdbcType="VARCHAR" />
<result column="LAST_LOGIN_TIME" property="lastLoginTime" jdbcType="TIMESTAMP" />
<result column="ONLINE_MARK" property="onlineMark" jdbcType="VARCHAR" />
<result column="ONLINE_IP" property="onlineIp" jdbcType="VARCHAR" />
<result column="SESSIONID" property="sessionid" jdbcType="VARCHAR" />
<collection property="opmRole" ofType="com.esteel.system.bean.OpmRole" select="getr" column="{uId=ID}">
</collection>
</resultMap>
<select id="getr" resultMap="BaseResultMapr">
select r.* from opm_role r join opm_user_role ur on ur.roleid = r.id join opm_User o on o.id = ur.userid
and o.id=#{uId}
</select>
<select id="getUserByMarkId" parameterType="map" resultMap="BaseResultMapVo">
select o.*
from opm_User o
where 1 = 1
<if test="organid!=null and organid!=''">
and o.organId=#{organid}
</if>
<if test="valid!=null and valid!=''">
and o.valid=#{valid}
</if>
<if test="level1!=null and level1!=''">
and o.LEVEL1=#{level1}
</if>
order by o.code
</select>
- mybaits两种关联查询
- mybaits 一对多 关联查询
- MyBaits关联查询一对一、一对多
- Mybaits---关于关联表数据查询
- [学习小结]Mybaits的关联表查询:一对一关联和一对多关联
- mybaits in查询使用
- Mybaits 动态查询数据库
- mybaits模糊查询
- Mybaits——DAO层开发两种模式
- sql 两表关联查询加分组
- yii relations 两表关联查询
- MyBatis配置一对一关联查询的两种方式及其双向获取时注意问题
- 关于springboot整合mybatis,做关联查询的两种方式(注解和配置文件)
- mybaits----多表查询实现
- 一个两表关联的复杂查询语句
- 查询两张关联表去除重复记录
- 查询两张通过ID关联的表
- SQL查询案例---两表关联更新使用VIEW
- fl2440内核移植过程Linux-3.0
- SuperMap iServer 微服务多实例
- mybatis关联查询(同名字段问题)
- Java线程:线程的交互
- ASN.1探索 - 3编码规则与传输语法(CER与DER)
- mybaits两种关联查询
- EntityFramework 启用迁移 Enable-Migrations 报异常 "No context type was found in the assembly"
- 深度学习算法之AlexNet和VGGNet
- 前台jsp对关联实体的遍历
- React笔记-todoList-Demo
- android中关闭软键盘
- c++中数字字符串的转换
- JUST SO SO之centOs 下 nginx安装
- oracle的SQL语句性能优化