实体如下:

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;    //备注
@Transientprivate String order;//排序字段
    @Transientprivate String orderType;//排序方法
    @Transientprivate String headImg;//首页图片
@Transientprivate List<String> imgUrlList;//接收前台URL集合使用
@Transientprivate Date shelfDate;//上架时间    接收前台字段
@Transientprivate Date obtainedDate;//下架时间        接收前台字段private String shelfRemark;//上架信息  备注
@Transientprivate 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>() {@Overridepublic 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 + "%"));}// ===========等于====================// uidString uid = entity.getUid();if (StringUtils.isNotBlank(uid)) {predicates.add(cb.equal(root.<String>get("uid"), uid));}// tidString 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; //积分商品idprivate Integer type; // 图片类型(1:首页展示,2:详情图片,3:自定义图片)private String src; // 图片路径private Integer sort; // 图片顺序private String tid;//租户idprivate String imgKey;//七牛云存储图片的keyprivate 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>() {@Overridepublic Predicate toPredicate(Root<IntegralGoodsImg> root, CriteriaQuery<?> query, CriteriaBuilder cb) {List<Predicate> predicates = new ArrayList<Predicate>();// ===========等于====================// uidString uid = entity.getUid();if (StringUtils.isNotBlank(uid)) {predicates.add(cb.equal(root.<String>get("uid"), uid));}// 积分商品idString 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));}//tidString 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_sortfrom integral_goods aleft joinintegral_goods_img bon a.uid = b.integral_goods_idleft joinshelf_log slon a.uid = sl.integral_goods_uid<where>a.delete_flag = ${@com.pisen.cloud.luna.ms.jifen.base.domain.IntegralGoods@DELETE_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}]}]
}

【mybatis】mybatis多表联查,存在一对多关系的,实体中使用List作为字段接收查询结果的写法...相关推荐

  1. 6.2 、MyBatis 高级映射(resultMap 标签多表联查 , 一对多,多对一关系)

    文章目录 一.创建表结构,添加数据,实现表中数据的关联关系 二. association 标签:用于一对一.多对一场景使用 1.实现一对一,多对一关系结果集映射 1.1 按照查询嵌套处理 1.2 按照 ...

  2. jpi多表联查_使用mybatis进行多表联查

    一.使用mybatis的基本步骤 1.导入jar包 2.配置文件 3.使用配置文件完成操作 二.实战演习 需求:教师表里有教师id和教师姓名 学生表里有学生id,姓名,年龄,教师id 一个教师有多个学 ...

  3. 使用mybatis进行四表联查

    文章目录 一.问题背景 二.实际问题 三.问题解决 四.sql语句与XML映射文件 五.测试 一.问题背景 先数据库有用户表user.角色表role.菜单表menu.功能表funs和角色菜单关系表ro ...

  4. MyBatis Plus多表联查方法

    MyBatis Plus是一款针对MyBatis框架的增强工具, 它提供了很多方便的方法来实现多表联查. 你可以使用MyBatis Plus的selectPage方法来实现多表联查, 该方法接收一个Q ...

  5. Mybatis实现多表联查

    一.Mybatis实现多表联查询 1.Mybatis实现多表联查询方式 业务装配对两个表写单独的sql语句,在业务(service)把查询结果进行联合. 使用Auto Mapping特性,在实现两个表 ...

  6. mysql表中的多对多关系表_「一对多」关系型数据库中一对多,多对一,多对多关系(详细) - seo实验室...

    一对多 在关系型数据库中,通过外键将表跟表之间联系在了一起. 一个班级有很多学生,外键维护在学生的一方,也就是多的一方.(在做页面设计的时候,需要把两个表连接到一块查询信息) 建立一个student和 ...

  7. jpi多表联查_使用Mybatis进行多表联查操作

    (1)增加一个测试数据库shop_order,sql语句如下: CREATE DATABASE`shop_order`;USE`shop_order`;CREATE TABLE`t_user` ( ` ...

  8. Mybatis多表联查简简单单

    Mybatis多表联查 1.一对一关系`association` 2.一对多关系`collection` 3.多对多关系 Mybatis中实现了对数据库中的数据进行封装,那么进行多表查询时就会遇到查询 ...

  9. Php Laravel框架 多表关系处理 之 Eloquent一对多关系处理

    Php Laravel框架 多表关系处理 之 Eloquent一对多关系处理 本博文主要介绍 Laravel 框架中 Eloquent  对一对多关系的处理以及在 Laravel Administra ...

最新文章

  1. 递归与分治——二分查找算法(折半查找算法)
  2. HTML与CSS基础之常用选择器(一)
  3. sqlserver 中事务与错误机制的处理
  4. python文件命名的错误
  5. XAML实例教程系列 - 类型转换器(Type Converter)
  6. exchange2003 SMTP连接器的应用案例
  7. android 按钮顶级效果_Android 中按钮的点击效果
  8. php redis hgetall 慢,redis的hGetAll函数的性能问题(记Redis那坑人的HGETALL)
  9. sci论文 计算机,计算机类SCI论文
  10. C51与MDK共存 Keil5安装教程
  11. 采用LM1875组成的各种功放电路
  12. sublime使用指南
  13. linux 搜狗输入法快捷键设置,Linux配置中文输入法(搜狗输入法)-Go语言中文社区...
  14. 南阳oj 题目72 Financial Management
  15. xcode9 IphoneX 调试
  16. 【ArcGIS】地表模型生成和显示
  17. XDOJ32角谷定理
  18. 1945:【09NOIP普及组】多项式输出
  19. android6.0屏蔽home键,android 禁用home键
  20. 商业智能BI与业务结构分析

热门文章

  1. python double free_python错误:double free或corruption(out):0x0000000001e4b030
  2. JAVA基础学习之路(十一)引用传递
  3. webstorm 不知道手贱点了什么,有时候会自动删除分号
  4. 2016和2017的区别就是昨晚和今早
  5. 【玩转Eclipse】——eclipse实现代码块折叠-类似于VS中的#region……#endregion
  6. Linux CentOS下安装Oracle
  7. [分享] 精神崩溃的老鼠
  8. 统一配置数据库连接符的方法
  9. dual mysql 获取序列_MySQL JDBC客户端反序列化漏洞
  10. powershell新建python文件_powershell如何打开Python