Mybatis关联查询结果集对象嵌套的具体使用
在查询时经常出现一对多”的关系,所有会出现嵌套对象的情况,Mybatis在resultMap提供了collection标签,本文适合有一定Mybatis基础的读者查阅
数据模型WeixinActivity2018User.java
public class WeixinActivity2018Userimplements Serializable{/** serialVersionUID*/private static final long serialVersionUID = -2740162776768956231L; private int id; private String nickname; //昵称private String headurl; //头像private String openid; //微信用户OpenIdprivate String unionid; private String phone; //用户手机号private int count; //积攒数private String createtime; //创建时间private String uptime; //更新时间private Listactivity2018UserAssists; //点赞用户信息
【Mybatis关联查询结果集对象嵌套的具体使用】数据模型WeixinActivity2018UserAssist.java
public class WeixinActivity2018UserAssistimplements Serializable{/** serialVersionUID*/private static final long serialVersionUID = -2740162776768956232L; private int aid; private int uid; private String nickname; private String headurl; private String openid; private String unionid; private String createtime;
WeixinActivity2018UserMapper.xml
openid,unionid,phone,nickname,headurl,count,createtime,uptime insert into t_weixin_activity_2018_user (openid,unionid,phone,nickname,headurl,createtime,uptime)values (#{openid,jdbcType=VARCHAR},#{unionid,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR}, #{headurl,jdbcType=VARCHAR},now(),now()) SELECTcount(twau.id)fromt_weixin_activity_2018_user twauand twau.openid = #{openid} and twau.id = #{id} and twau.phone = #{phone} SELECT twau.id,twau.openid, twau.unionid, twau.phone, twau.nickname, twau.headurl, twau.count,date_format( twau.createtime, '%Y-%m-%d %H:%m:%s') as createtime,date_format( twau.uptime, '%Y-%m-%d %H:%m:%s') as uptime,twaua.aid,twaua.uid,twaua.openid as aopenid,twaua.unionid as aunionid,twaua.nickname as anickname,twaua.headurl as aheadurl,date_format(twaua.createtime, '%Y-%m-%d %H:%m:%s') as acreatetime ,twaua.phone as aphonefromt_weixin_activity_2018_user twau LEFTJOIN t_weixin_activity_2018_user_assist twaua on twau.id=twaua.uidwhere 1=1and twau.openid = #{openid} and twau.id = #{id} and twau.phone = #{phone} order by tlb.createtime desc limit ${start}, ${number}
到此这篇关于Mybatis关联查询结果集对象嵌套的具体使用的文章就介绍到这了,更多相关Mybatis关联查询对象嵌套 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 提高跨库查询速度,你只需一个Smartbi
- 《吃透Mybatis源码》|吃透Mybatis源码-缓存的理解(三)
- 使用Mybatis如何实现删除多个数据
- 二本计算机专业录取分数查询,二本录取查询
- 学习经历|cgb2107-第三阶段-day03-Mybatis入门
- 图数据库笔记(NebulaGraph的基础查询)
- mybatis|mybatis resultMap没有全部对应的字段处理方式
- 基于mybatis|基于mybatis plus实现数据源动态添加、删除、切换,自定义数据源的示例代码
- 使用MASA|使用MASA Blazor开发一个标准的查询表格页
- Mybatis|Mybatis plus关闭驼峰命名的四种方法(防止出现查询为Null)