欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mybatis關聯(lián)查詢結果集對象嵌套的具體使用

 更新時間:2022年02月23日 09:47:45   作者:FANQIBU  
在查詢時經常出現一對多”的關系,所有會出現嵌套對象的情況,本文主要介紹了Mybatis關聯(lián)查詢結果集對象嵌套的具體使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

在查詢時經常出現一對多”的關系,所有會出現嵌套對象的情況,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;//創(chuàng)建時間
? ? private String uptime; ? ?//更新時間
? ? private List<WeixinActivity2018UserAssist> activity2018UserAssists;//點贊用戶信息

數據模型WeixinActivity2018UserAssist.java

public class WeixinActivity2018UserAssist ?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

? <resultMap id="BaseResultMap" type="com.lh.wx.model.WeixinActivity2018User">
? ? <id column="id" jdbcType="INTEGER" property="id" />
? ? <result column="openid" jdbcType="VARCHAR" property="openid" />
? ? <result column="unionid" jdbcType="VARCHAR" property="unionid" />
? ? <result column="phone" jdbcType="VARCHAR" property="phone" />
? ? <result column="nickname" jdbcType="VARCHAR" property="nickname" />
? ? <result column="headurl" jdbcType="VARCHAR" property="headurl" />
? ? <result column="count" jdbcType="INTEGER" property="count" />
? ? <result column="createtime" jdbcType="DATE" property="createtime" />
? ? <result column="uptime" jdbcType="DATE" property="uptime" />
? ? <collection ?property="activity2018UserAssists" ?ofType="com.lh.wx.model.WeixinActivity2018UserAssist">
? ? ? ? ? ? <id property="aid" column="aid" />
? ? ? ? ? ? ?<result column="uid" jdbcType="INTEGER" property="uid" />
? ? ? ? ? ? <result column="aopenid" jdbcType="VARCHAR" property="openid" />
? ? ? ? ? ? <result column="aunionid" jdbcType="VARCHAR" property="unionid" />
? ? ? ? ? ? <result column="anickname" jdbcType="VARCHAR" property="nickname" />
? ? ? ? ? ? <result column="aheadurl" jdbcType="VARCHAR" property="headurl" />
? ? ? ? ? ? <result column="acreatetime" jdbcType="DATE" property="createtime" />
? ? </collection>
? </resultMap>
? <sql id="Base_Column_List">
? ? openid,unionid,phone,nickname,headurl,count,createtime,uptime
? </sql>
? <insert id="insertActivity2018User" ?useGeneratedKeys="true" keyProperty="id" parameterType="com.lh.wx.model.WeixinActivity2018User" >
? ? 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()
? ? )
? </insert>
? ? <select id="selectTalCount" resultType="java.lang.Integer" ?parameterType="java.util.Map">
? ? ? ? SELECT ?count(twau.id)
? ? ? ? from ?t_weixin_activity_2018_user twau
? ? ? ? <if test="openid != '' and openid != null">
? ? ? ? ? ? and twau.openid = #{openid}
? ? ? ? </if>
? ? ? ? <if test="id != 0 and id != null">
? ? ? ? ? ? and twau.id = #{id}
? ? ? ? </if>
? ? ? ? <if test="phone != '' and phone != null">
? ? ? ? ? ? and twau.phone = #{phone}
? ? ? ? </if>
? ? </select>
? ? <select id="queryActivity2018User" parameterType="java.util.Map" resultMap="BaseResultMap" >
? ? ? ? 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 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
? ? ? ? <if test="openid != '' and openid != null">
? ? ? ? ? ? and twau.openid = #{openid}
? ? ? ? </if>
? ? ? ? <if test="id != 0 and id != null">
? ? ? ? ? ? and twau.id = #{id}
? ? ? ? </if>
? ? ? ? <if test="phone != '' and phone != null">
? ? ? ? ? ? and twau.phone = #{phone}
? ? ? ? </if>
? ? ? ? <if test="start != '' and start != null ?and start != 0">
? ? ? ? ? ? order by tlb.createtime desc limit ${start}, ${number}
? ? ? ? </if>
? </select>

到此這篇關于Mybatis關聯(lián)查詢結果集對象嵌套的具體使用的文章就介紹到這了,更多相關Mybatis關聯(lián)查詢對象嵌套 內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 基于google zxing的Java二維碼生成與解碼

    基于google zxing的Java二維碼生成與解碼

    這篇文章主要為大家詳細介紹了基于google zxing的Java二維碼生成與解碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 詳解Springboot2.3集成Spring security 框架(原生集成)

    詳解Springboot2.3集成Spring security 框架(原生集成)

    這篇文章主要介紹了詳解Springboot2.3集成Spring security 框架(原生集成),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • Java中&與&&的區(qū)別及說明

    Java中&與&&的區(qū)別及說明

    這篇文章主要介紹了Java中&與&&的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • 詳解springboot shiro jwt實現權限管理

    詳解springboot shiro jwt實現權限管理

    為什么使用jwt呢,因為可以通過URL,POST參數或者在HTTP header發(fā)送,因為數據量小,傳輸速度也很快。本篇通過具體代碼來進行詳情解析,對大家的學習或工作具有一定的參考借鑒價值
    2021-09-09
  • SpringBoot整合Hibernate Validator實現參數驗證功能

    SpringBoot整合Hibernate Validator實現參數驗證功能

    這篇文章主要介紹了SpringBoot整合Hibernate Validator實現參數驗證功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-06-06
  • SpringCloudAlibaba整合Feign實現遠程HTTP調用的簡單示例

    SpringCloudAlibaba整合Feign實現遠程HTTP調用的簡單示例

    這篇文章主要介紹了SpringCloudAlibaba 整合 Feign 實現遠程 HTTP 調用,文章中使用的是OpenFeign,是Spring社區(qū)開發(fā)的組件,需要的朋友可以參考下
    2021-09-09
  • Java常用的時間類以及其轉化方式

    Java常用的時間類以及其轉化方式

    這篇文章主要介紹了Java常用的時間類以及其轉化方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Spring中的IOC深度解讀

    Spring中的IOC深度解讀

    這篇文章主要介紹了Spring中的IOC深度解讀,spring容器會創(chuàng)建和組裝好清單中的對象,然后將這些對象存放在spring容器中,當程序中需要使用的時候,可以到容器中查找獲取,然后直接使用,需要的朋友可以參考下
    2023-09-09
  • Java中ThreadLocal線程變量的實現原理

    Java中ThreadLocal線程變量的實現原理

    本文主要介紹了Java中ThreadLocal線程變量的實現原理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • SpringBoot控制配置類加載順序方式

    SpringBoot控制配置類加載順序方式

    這篇文章主要介紹了SpringBoot控制配置類加載順序方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05

最新評論