Mybatis关联查询结果集对象嵌套的具体使用

网友投稿 737 2022-10-28

Mybatis关联查询结果集对象嵌套的具体使用

Mybatis关联查询结果集对象嵌套的具体使用

在查询时经常出现一对多”的关系,所有会出现嵌套对象的情况,Mybatis在resultMap提供了collection标签,本文适合有一定Mybatis基础的读者查阅

数据模型WeixinActivity2018User.java

public class WeixinActivity2018User implements Serializable{

/** serialVersionUID*/

private static final long serialVersionUID = -2740162776768956231L;

private int id;

private String nickname; //昵称

private String headurl; //头像

private String openid; //微信用户OpenId

private String unionid;

private String phone; //用户手机号

private int count; //积攒数

private String createtime;//创建时间

private String uptime; //更新时间

private List activity2018UserAssists;//点赞用户信息

数据模型WeixinActivity2018UserAssist.java

public class WeixinAAcIspctivity2018UserAssist implements 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()

)

SELECT count(twau.id)

from t_weixin_activity_2018_user twau

and 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 acrhttp://eatetime ,

twaua.phonAcIspe as aphone

from t_weixin_activity_2018_user twau LEFT JOIN t_weixin_activity_2018_user_assist twaua on twau.id=twaua.uid where 1=1

and twau.openid = #{openid}

and twau.id = #{id}

and twau.phone = #{phone}

order by tlb.createtime desc limit ${start}, ${number}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:JVM规范系列第4章:Class文件格式
下一篇:AnimTrap是一个实现Web动画的CSS和JS框架
相关文章

 发表评论

暂时没有评论,来抢沙发吧~