mybatismybatis多表联查,存在一对多关系的,实体中使用List作为字段接收查询结果的写法

Posted Angel挤一挤

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatismybatis多表联查,存在一对多关系的,实体中使用List作为字段接收查询结果的写法相关的知识,希望对你有一定的参考价值。

 

实体如下:

IntegralGoods  积分商品

IntegralGoodsImg  积分商品图片

ShelfLog    积分商品自动上架记录

 

IntegralGoods :IntegralGoodsImg:ShelfLog  = 1:n:1

1:1的多表联查或者m:n的多表联查 很简单,

现在出现1:n的情况,一种积分商品可能有多张图片

所以在最后的返回结果里想用LIst<IntegralGoodsImg>作为IntegralGoods 的一个字段作为参数进行接收

 

那mybatis怎么实现查询呢?

=========================================================

1.IntegralGoods 实体【只关注字段即可】,尤其是

 

@Transient

private List<IntegralGoodsImg> imgList;//图片们 

这个字段就是用来接收多个图片实体的

技术分享图片
package com.pisen.cloud.luna.ms.jifen.base.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Type;
import org.springframework.data.jpa.domain.Specification;

import com.pisen.cloud.luna.ms.jifen.base.common.BaseDomain;

/**
 * 积分商品表
 */
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "uid" })})
public class IntegralGoods extends BaseDomain {

    public static final int DELETE_FLAG_DELETE = 1;//删除

    public static final int DELETE_FLAG_DISDELETE = 0;//未删除

    public static final int SHELF_ON = 1;//上架

    public static final int SHELF_OFF = 0;//下架

    public static final int SHOW_HOME_FLAG_YES = 1;//首页展示

    public static final int SHOW_HOME_FLAG_NO = 0;//不在首页展示


    @Type(type = "text")
    private String description; //商品描述


    private String cdKey;//虚拟物品激活码 ---弃用

    @Column(nullable = false)
    private String name; // 名称

    @Column(nullable = false)
    private Float marketValue; // 原价

    @Column(nullable = false)
    private Integer integral; // 兑换积分

    private Integer type; // (1:实物 2:虚拟)

    @Column(nullable = false)
    private Integer stock; // 库存数量(-1时无限量 : 正常扣除)

    @Column(nullable = false)
    private Integer saleNum; // 销量 已兑换数量


    
    private Integer version;


    /**
     * ========新增字段===================
     */
    @Column(nullable = false)
    private Integer limitNum;//限兑数量

    private String goodsCode;//商品编号

    @Column(nullable = false)
    private String specification;//商品规格  实物商品必填

    private Integer deleteFlag;//删除标识

    @Column(nullable = false)
    private Integer shelfFlag;//上架标识

    @Column(nullable = false)
    private Integer homeShowFlag;//是否首页展示

    private String remark;    //备注

    
    @Transient
    private String order;//排序字段
    @Transient
    private String orderType;//排序方法
    @Transient
    private String headImg;//首页图片

    @Transient
    private List<String> imgUrlList;//接收前台URL集合使用

    @Transient
    private Date shelfDate;//上架时间    接收前台字段

    @Transient
    private Date obtainedDate;//下架时间        接收前台字段

    private String shelfRemark;//上架信息  备注

    @Transient
    private List<IntegralGoodsImg> imgList;//图片们


    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getShelfRemark() {
        return shelfRemark;
    }

    public void setShelfRemark(String shelfRemark) {
        this.shelfRemark = shelfRemark;
    }

    public Integer getHomeShowFlag() {
        return homeShowFlag;
    }

    public void setHomeShowFlag(Integer homeShowFlag) {
        this.homeShowFlag = homeShowFlag;
    }

    public Integer getShelfFlag() {
        return shelfFlag;
    }

    public void setShelfFlag(Integer shelfFlag) {
        this.shelfFlag = shelfFlag;
    }

    public Integer getLimitNum() {
        return limitNum;
    }

    public void setLimitNum(Integer limitNum) {
        this.limitNum = limitNum;
    }

    public String getGoodsCode() {
        return goodsCode;
    }

    public void setGoodsCode(String goodsCode) {
        this.goodsCode = goodsCode;
    }

    public String getSpecification() {
        return specification;
    }

    public void setSpecification(String specification) {
        this.specification = specification;
    }


    public Integer getDeleteFlag() {
        return deleteFlag;
    }

    public void setDeleteFlag(Integer deleteFlag) {
        this.deleteFlag = deleteFlag;
    }

    public List<IntegralGoodsImg> getImgList() {
        return imgList;
    }

    public void setImgList(List<IntegralGoodsImg> imgList) {
        this.imgList = imgList;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getOrderType() {
        return orderType;
    }

    public void setOrderType(String orderType) {
        this.orderType = orderType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getIntegral() {
        return integral;
    }

    public void setIntegral(Integer integral) {
        this.integral = integral;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCdKey() {
        return cdKey;
    }

    public void setCdKey(String cdKey) {
        this.cdKey = cdKey;
    }


    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }


    public Float getMarketValue() {
        return marketValue;
    }

    public void setMarketValue(Float marketValue) {
        this.marketValue = marketValue;
    }
    
    public String getHeadImg() {
        
        if(imgList != null){
            for (IntegralGoodsImg integralGoodsImg : imgList) {
                if(integralGoodsImg.getType() == 1){
                    headImg = integralGoodsImg.getSrc();
                    break;
                }
            }
        }
        
        return headImg;
    }

    public void setHeadImg(String headImg) {
        this.headImg = headImg;
    }

    public Integer getSaleNum() {
        return saleNum;
    }

    public void setSaleNum(Integer saleNum) {
        this.saleNum = saleNum;
    }

    public List<String> getImgUrlList() {
        return imgUrlList;
    }

    public void setImgUrlList(List<String> imgUrlList) {
        this.imgUrlList = imgUrlList;
    }

    public Date getShelfDate() {
        return shelfDate;
    }

    public void setShelfDate(Date shelfDate) {
        this.shelfDate = shelfDate;
    }

    public Date getObtainedDate() {
        return obtainedDate;
    }

    public void setObtainedDate(Date obtainedDate) {
        this.obtainedDate = obtainedDate;
    }

    public static Specification<IntegralGoods> where(final IntegralGoods entity) {
        return new Specification<IntegralGoods>() {

            @Override
            public Predicate toPredicate(Root<IntegralGoods> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

                List<Predicate> predicates = new ArrayList<Predicate>();

                //商品名称
                String name = entity.getName();
                if (StringUtils.isNotBlank(name)) {
                    predicates.add(cb.like(root.<String>get("name"), "%" + name + "%"));
                }

                // ===========等于====================
                // uid
                String uid = entity.getUid();
                if (StringUtils.isNotBlank(uid)) {
                    predicates.add(cb.equal(root.<String>get("uid"), uid));
                }

                // tid
                String tid = entity.getTid();
                if (StringUtils.isNotBlank(tid)) {
                    predicates.add(cb.equal(root.<String>get("tid"), tid));
                }

                // 积分
                Integer integral = entity.getIntegral();
                if (integral != null) {
                    predicates.add(cb.equal(root.<String>get("integral"), integral));
                }

                // 类型
                Integer type = entity.getType();
                if (type != null) {
                    predicates.add(cb.equal(root.<String>get("type"), type));
                }

                //库存
                Integer stock = entity.getStock();
                if (stock != null) {
                    predicates.add(cb.equal(root.<String>get("stock"), stock));
                }
                //激活码
                String cdKey = entity.getCdKey();
                if (StringUtils.isNotBlank(cdKey)){
                    predicates.add(cb.equal(root.get("cdKey"),cdKey));
                }

                //商品编号
                String goodsCode = entity.getGoodsCode();
                if (StringUtils.isNotBlank(goodsCode)){
                    predicates.add(cb.equal(root.get("goodsCode"),goodsCode));
                }

                //上架标识
                Integer shelfFlag = entity.getShelfFlag();
                if (shelfFlag != null){
                    predicates.add(cb.equal(root.get("shelfFlag"),shelfFlag));
                }


                return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
            }
        };
    }

}
View Code

 

2.IntegralGoodsImg实体

技术分享图片
package com.pisen.cloud.luna.ms.jifen.base.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.jpa.domain.Specification;

import com.pisen.cloud.luna.ms.jifen.base.common.BaseDomain;

@Entity
@Table(uniqueConstraints = { 
        @UniqueConstraint(columnNames = { "uid" }),
        @UniqueConstraint(columnNames = { "imgKey" })
    })
public class IntegralGoodsImg extends BaseDomain {

    public static final int IMG_TYPE_MAIN = 1;//商品主图

    public static final int IMG_TYPE_OTHER = 2;//其他商品图片

    
    private String integralGoodsId; //积分商品id
    
    private Integer type; // 图片类型(1:首页展示,2:详情图片,3:自定义图片)
    
    private String src; // 图片路径
    
    private Integer sort; // 图片顺序
    
    private String tid;//租户id
    
    private String imgKey;//七牛云存储图片的key
    
    private String imgName; //用户上传的文件名
    
    
    public String getIntegralGoodsId() {
        return integralGoodsId;
    }

    public void setIntegralGoodsId(String integralGoodsId) {
        this.integralGoodsId = integralGoodsId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getSrc() {
        return src;
    }

    public void setSrc(String src) {
        this.src = src;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }
    
    public String getTid() {
        return tid;
    }

    public void setTid(String tid) {
        this.tid = tid;
    }
    
    public String getImgKey() {
        return imgKey;
    }

    public void setImgKey(String imgKey) {
        this.imgKey = imgKey;
    }
    
    public String getImgName() {
        return imgName;
    }

    public void setImgName(String imgName) {
        this.imgName = imgName;
    }

    public static Specification<IntegralGoodsImg> where(final IntegralGoodsImg entity) {
        return new Specification<IntegralGoodsImg>() {

            @Override
            public Predicate toPredicate(Root<IntegralGoodsImg> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                
                List<Predicate> predicates = new ArrayList<Predicate>();
                
                
                
                // ===========等于====================
                // uid
                String uid = entity.getUid();
                if (StringUtils.isNotBlank(uid)) {
                    predicates.add(cb.equal(root.<String>get("uid"), uid));
                }
                
                // 积分商品id
                String integralGoodsId = entity.getIntegralGoodsId();
                if (StringUtils.isNotBlank(integralGoodsId)) {
                    predicates.add(cb.equal(root.<String>get("integralGoodsId"), integralGoodsId));
                }
                
                // 图片类型
                Integer type = entity.getType();
                if (type != null) {
                    predicates.add(cb.equal(root.<String>get("type"), type));
                }
                
                //tid
                String tid = entity.getTid();
                if (StringUtils.isNotBlank(tid)) {
                    predicates.add(cb.equal(root.<String>get("tid"), tid));
                }
                
                return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
            }
        };
    }
    
    
}
View Code

 

3.ShelfLog实体

技术分享图片
package com.pisen.cloud.luna.ms.jifen.base.domain;

import javax.persistence.*;
import java.util.Date;

/**
 * 自动上架 下架时间 记录表
 *
 * 单位控制到天
 *
 * 定时任务每天定时扫描 完成积分商品自动上架下架状态的改变
 */
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "integralGoodsUid" })})
public class ShelfLog {


    public static final int DEAL_FLAG_DO = 1;//已处理

    public static final int DEAL_FLAG_NOT_HAVING_DO = 0;//未处理

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;// 主键 自增

    @Column(nullable = false)
    private String integralGoodsUid;//积分商品ID    本记录表中唯一

    private Date shelfDate;//自定义自动上架时间

    private Date obtainedDate;//自定义自动下架时间

    private Integer shelfDealFlag;//上架是否处理

    private Integer obtainedFlag;//下架是否处理


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getIntegralGoodsUid() {
        return integralGoodsUid;
    }

    public void setIntegralGoodsUid(String integralGoodsUid) {
        this.integralGoodsUid = integralGoodsUid;
    }

    public Date getShelfDate() {
        return shelfDate;
    }

    public void setShelfDate(Date shelfDate) {
        this.shelfDate = shelfDate;
    }

    public Date getObtainedDate() {
        return obtainedDate;
    }

    public void setObtainedDate(Date obtainedDate) {
        this.obtainedDate = obtainedDate;
    }

    public Integer getShelfDealFlag() {
        return shelfDealFlag;
    }

    public void setShelfDealFlag(Integer shelfDealFlag) {
        this.shelfDealFlag = shelfDealFlag;
    }

    public Integer getObtainedFlag() {
        return obtainedFlag;
    }

    public void setObtainedFlag(Integer obtainedFlag) {
        this.obtainedFlag = obtainedFlag;
    }

}
View Code

 

 

4.最后着重看mybatis的xml怎么写

技术分享图片
<select id="find" parameterType="com.pisen.cloud.luna.ms.jifen.base.domain.IntegralGoods" resultMap="baseResBean">
    
        select 
            a.id as ‘id‘,
            a.uid as ‘uid‘,
            a.create_date as ‘createDate‘,
            a.update_date as ‘updateDate‘,
            a.update_id as ‘updateId‘,
            a.create_id as ‘createId‘,
            a.brand_uid as ‘brandUid‘,
            a.tid as ‘tid‘,
            a.stock as ‘stock‘,
            a.name as ‘name‘,
            a.goods_code as ‘goodsCode‘,
            a.market_value as ‘marketValue‘,
            a.specification as ‘specification‘,
            a.remark as ‘remark‘,
            a.integral as ‘integral‘,
            a.description as ‘description‘,
            a.sale_num as ‘saleNum‘,
            a.limit_num as ‘limitNum‘,
            a.shelf_flag as ‘shelfFlag‘,
            a.home_show_flag as ‘homeShowFlag‘,
            sl.shelf_date as ‘shelfDate‘,
            sl.obtained_date as ‘obtainedDate‘,
            b.src b_src,
            b.type b_type,
            b.sort  b_sort
        from 
            integral_goods a
        left join
            integral_goods_img b
        on 
            a.uid = b.integral_goods_id
        left join
            shelf_log sl
        on a.uid = sl.integral_goods_uid
        <where>
            a.delete_flag = ${@[email protected]_FLAG_DISDELETE}
            and a.tid = #{tid}

        <if test="uid != null and uid != ‘‘ ">
            and a.uid = #{uid}
        </if>

        <if test="brandUid != null and brandUid != ‘‘ ">
            and a.brand_uid = #{brandUid}
        </if>
    
        <if test="name != null and name != ‘‘ ">
            and a.name like CONCAT(‘%‘,#{name},‘%‘)
        </if>

        </where>
    
    </select>

    <resultMap type="com.pisen.cloud.luna.ms.jifen.base.domain.IntegralGoods" id="baseResBean">
    
        <id column="id" property="id"/>
        <result column="uid" property="uid"/>
        <result column="createDate" property="createDate"/>
        <result column="updateDate" property="updateDate"/>
        <result column="createId" property="createId"/>
        <result column="updateId" property="updateId"/>
        <result column="type" property="type"/>
        <result column="tid" property="tid"/>
        <result column="stock" property="stock"/>
        <result column="name" property="name"/>
        <result column="goodsCode" property="goodsCode"/>
        <result column="marketValue" property="marketValue"/>
        <result column="specification" property="specification"/>
        <result column="brandUid" property="brandUid"/>
        <result column="remark" property="remark"/>
        <result column="integral" property="integral"/>
        <result column="description" property="description"/>
        <result column="saleNum" property="saleNum"/>
        <result column="limitNum" property="limitNum"/>
        <result column="shelfFlag" property="shelfFlag"/>
        <result column="homeShowFlag" property="homeShowFlag"/>
        <result column="shelfDate" property="shelfDate"/>
        <result column="obtainedDate" property="obtainedDate"/>
        
        <collection 
            property="imgList" 
            columnPrefix="b_"
            ofType="com.pisen.cloud.luna.ms.jifen.base.domain.IntegralGoodsImg"
            >
            <id column="id" property="id"/>
            <result column="src" property="src"/>
            <result column="type" property="type"/>
            <result column="sort" property="sort"/>

        </collection>
        
        
    </resultMap>
View Code

 

5.最后补充一下mapper.java

List<IntegralGoods> find(IntegralGoods entity);

 

展示一下最后的查询结果:【注意最后的total总数有问题,需要单独处理一下】

【total=8表示数据库中查出的数据是8条,在组装返回List以后,就是3条了】

{
    "success": true,
    "msg": "successful",
    "code": 200,
    "total": 8,
    "rows": [
        {
            "fields": null,
            "orders": null,
            "pageSize": 10,
            "pageNum": 0,
            "id": 48,
            "createDate": 1533689800000,
            "updateDate": 1533689800000,
            "updateId": "defUserId",
            "createId": "defUserId",
            "uid": "42832f275248456f8a8ff6b855f55e95",
            "tid": "9f63f84f-52c6-4c8e-b3c3-66b9f1f283ba",
            "brandUid": "974fcd3a139f4b19a632bc40b6eec7b9",
            "description": null,
            "cdKey": null,
            "name": "统一方便面",
            "marketValue": 100,
            "integral": 100,
            "type": null,
            "stock": 200,
            "saleNum": 0,
            "version": null,
            "limitNum": 2,
            "goodsCode": null,
            "specification": "105g/桶*12桶/件",
            "deleteFlag": null,
            "shelfFlag": 0,
            "homeShowFlag": 1,
            "remark": null,
            "order": null,
            "orderType": null,
            "headImg": "http://p2ognrwoi.bkt.clouddn.com/fed69bb7be9416ed56916aea8ffad38f_UI_UPLOAD_IMG?e=1533562337&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:96nPcK9nruoaT3s_rNEzlQJrQeQ=?imageView2/1/w/50/h/50",
            "imgUrlList": null,
            "shelfDate": 1533859200000,
            "obtainedDate": 1533945600000,
            "shelfRemark": null,
            "imgList": [
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803047,
                    "updateDate": 1533698803047,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 1,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/fed69bb7be9416ed56916aea8ffad38f_UI_UPLOAD_IMG?e=1533562337&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:96nPcK9nruoaT3s_rNEzlQJrQeQ=?imageView2/1/w/50/h/50",
                    "sort": 1,
                    "imgKey": null,
                    "imgName": null
                },
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803052,
                    "updateDate": 1533698803052,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 2,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/b07121eeadc1e42dbde765af569356a3_UI_UPLOAD_IMG?e=1533563250&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:W_EObH6d7O_QrqRQeX1CSmba0KE=?imageView2/1/w/50/h/50",
                    "sort": 2,
                    "imgKey": null,
                    "imgName": null
                },
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803055,
                    "updateDate": 1533698803055,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 2,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/237d4a191de7b25897cdb49117dfb9ec_UI_UPLOAD_IMG?e=1533563617&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:M3FJDLzza80U72934OT7B8ya_Yw=?imageView2/1/w/50/h/50",
                    "sort": 3,
                    "imgKey": null,
                    "imgName": null
                }
            ]
        },
        {
            "fields": null,
            "orders": null,
            "pageSize": 10,
            "pageNum": 0,
            "id": 49,
            "createDate": 1533698513000,
            "updateDate": 1533698513000,
            "updateId": "defUserId",
            "createId": "defUserId",
            "uid": "17c2050b247a45f0ae092d48b035c9e5",
            "tid": "9f63f84f-52c6-4c8e-b3c3-66b9f1f283ba",
            "brandUid": "974fcd3a139f4b19a632bc40b6eec7b9",
            "description": null,
            "cdKey": null,
            "name": "统一方便面",
            "marketValue": 100,
            "integral": 100,
            "type": null,
            "stock": 200,
            "saleNum": 0,
            "version": null,
            "limitNum": 2,
            "goodsCode": null,
            "specification": "105g/桶*12桶/件",
            "deleteFlag": null,
            "shelfFlag": 0,
            "homeShowFlag": 1,
            "remark": null,
            "order": null,
            "orderType": null,
            "headImg": "http://p2ognrwoi.bkt.clouddn.com/fed69bb7be9416ed56916aea8ffad38f_UI_UPLOAD_IMG?e=1533562337&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:96nPcK9nruoaT3s_rNEzlQJrQeQ=?imageView2/1/w/50/h/50",
            "imgUrlList": null,
            "shelfDate": 1533859200000,
            "obtainedDate": null,
            "shelfRemark": null,
            "imgList": [
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803068,
                    "updateDate": 1533698803068,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 1,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/fed69bb7be9416ed56916aea8ffad38f_UI_UPLOAD_IMG?e=1533562337&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:96nPcK9nruoaT3s_rNEzlQJrQeQ=?imageView2/1/w/50/h/50",
                    "sort": 1,
                    "imgKey": null,
                    "imgName": null
                },
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803070,
                    "updateDate": 1533698803070,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 2,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/b07121eeadc1e42dbde765af569356a3_UI_UPLOAD_IMG?e=1533563250&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:W_EObH6d7O_QrqRQeX1CSmba0KE=?imageView2/1/w/50/h/50",
                    "sort": 2,
                    "imgKey": null,
                    "imgName": null
                }
            ]
        },
        {
            "fields": null,
            "orders": null,
            "pageSize": 10,
            "pageNum": 0,
            "id": 46,
            "createDate": 1533689464000,
            "updateDate": 1533689464000,
            "updateId": "defUserId",
            "createId": "defUserId",
            "uid": "629669683bf34ecdbb81ac8bbc236845",
            "tid": "9f63f84f-52c6-4c8e-b3c3-66b9f1f283ba",
            "brandUid": "974fcd3a139f4b19a632bc40b6eec7b9",
            "description": null,
            "cdKey": null,
            "name": "统一方便面",
            "marketValue": 100,
            "integral": 100,
            "type": null,
            "stock": 200,
            "saleNum": 0,
            "version": null,
            "limitNum": 2,
            "goodsCode": null,
            "specification": "105g/桶*12桶/件",
            "deleteFlag": null,
            "shelfFlag": 0,
            "homeShowFlag": 1,
            "remark": null,
            "order": null,
            "orderType": null,
            "headImg": "http://p2ognrwoi.bkt.clouddn.com/fed69bb7be9416ed56916aea8ffad38f_UI_UPLOAD_IMG?e=1533562337&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:96nPcK9nruoaT3s_rNEzlQJrQeQ=?imageView2/1/w/50/h/50",
            "imgUrlList": null,
            "shelfDate": null,
            "obtainedDate": null,
            "shelfRemark": null,
            "imgList": [
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803082,
                    "updateDate": 1533698803082,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 1,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/fed69bb7be9416ed56916aea8ffad38f_UI_UPLOAD_IMG?e=1533562337&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:96nPcK9nruoaT3s_rNEzlQJrQeQ=?imageView2/1/w/50/h/50",
                    "sort": 1,
                    "imgKey": null,
                    "imgName": null
                },
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803085,
                    "updateDate": 1533698803085,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 2,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/b07121eeadc1e42dbde765af569356a3_UI_UPLOAD_IMG?e=1533563250&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:W_EObH6d7O_QrqRQeX1CSmba0KE=?imageView2/1/w/50/h/50",
                    "sort": 2,
                    "imgKey": null,
                    "imgName": null
                },
                {
                    "fields": null,
                    "orders": null,
                    "pageSize": 10,
                    "pageNum": 0,
                    "id": null,
                    "createDate": 1533698803088,
                    "updateDate": 1533698803088,
                    "updateId": null,
                    "createId": null,
                    "uid": null,
                    "tid": null,
                    "brandUid": null,
                    "integralGoodsId": null,
                    "type": 2,
                    "src": "http://p2ognrwoi.bkt.clouddn.com/237d4a191de7b25897cdb49117dfb9ec_UI_UPLOAD_IMG?e=1533563617&token=lPDJgKX4JP-SQBa1EWaSt88UJAOpkW1n0JGv3gCQ:M3FJDLzza80U72934OT7B8ya_Yw=?imageView2/1/w/50/h/50",
                    "sort": 3,
                    "imgKey": null,
                    "imgName": null
                }
            ]
        }
    ]
}

 

以上是关于mybatismybatis多表联查,存在一对多关系的,实体中使用List作为字段接收查询结果的写法的主要内容,如果未能解决你的问题,请参考以下文章

MyBatis多表联查

MySQL 基础之 单表多表联查

mongoDB多表联查以及MongoTemplate的表联查API使用

mongoDB多表联查以及MongoTemplate的表联查API使用

mongoDB多表联查以及MongoTemplate的表联查API使用

mybatis资源的整合以及后续使用