【mybatis】mybatis多表联查,存在一对多关系的,实体中使用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();
}
};
} }
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();
}
};
} }
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;
} }
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 = ${@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>
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作为字段接收查询结果的写法的更多相关文章
- mybatis.net 多表联查
mybatis.net针对多表联查,其实不用讲联查出的所有的列全部做一个新的resultMap,我们完全可以通过集成关系来实现,真是上一次说的懒加载,在一定程度上可以提高其性能,但这并不是说懒加载性能 ...
- mybatis的多表联查
多对一连表查询简单记录
- 一对多关系domain Model中设置使用AutoMapper时出错
在使用AutoMapper时,把数据从VO-PO时显示如下错误,错误提示说在一对多关系中已将集合设置为EntityCollection,那么这个是为什么呢. 看下action中的代码,我们可以发现这是 ...
- mybatis实现多表一对一,一对多,多对多关联查询
原文:https://blog.csdn.net/m0_37787069/article/details/79247321 1.一对一关键字:association作用:针对pojo对象属性的映射 ...
- 使用Mybatis进行多表联查操作
(1)增加一个测试数据库shop_order,sql语句如下: CREATE DATABASE `shop_order`; USE `shop_order`; CREATE TABLE `t_user ...
- 阶段3 1.Mybatis_09.Mybatis的多表操作_3 完成account的一对一操作-通过写account的子类方式查询
先把多表查询的sql语句写出来 想要显示的字段 创建一个AccountUser类 继承Account.这样它就会从父类上继承一些信息 这里只需要定义username和address就可以了 .然后生成 ...
- Hibernate 多表关联映射- 一对多关系映射(one-to-many)
Hibernage.cfg.xml: <hibernate-configuration> <session-factory name="sessionFactory&quo ...
- MyBatis的多表查询笔记
MyBatis的多表查询 随着学习的进步,需求的提高,我们在实际开发中用的最多的还是多表查询,就让我们一起学习MyBatis中的多表查询. 数据库准备 Class表 Student表 项目结构 这次使 ...
- Mybatis框架中实现双向一对多关系映射
学习过Hibernate框架的伙伴们很容易就能简单的配置各种映射关系(Hibernate框架的映射关系在我的blogs中也有详细的讲解),但是在Mybatis框架中我们又如何去实现 一对多的关系映射呢 ...
随机推荐
- .build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)'
CXX/LD -o .build_release/tools/convert_imageset.bin.build_release/lib/libcaffe.so: undefined referen ...
- 阿里CDN核心技术解密
1. 阿里CDN组件分层 其中应用层主要用到的技术有负载均衡和缓存, 负载均衡包括全局负载均衡和本地负载均衡; 缓存通过HTTP缓存服务器Swift做HTTP缓存. 全局负载均衡以DNS服务器Phar ...
- [ python ] hasattr()、getattr()、setattr() 三者关系及运用
hasattr(object, name) 判断一个对象(object)是否存在name属性或方法,返回boolean值,有name属性返回True, 否则返回False In [1]: class ...
- IntelJ IDEA 进行Java Web开发+热部署+一些开发上的问题
基本上像放弃MyEclipse或者Eclipse了,因为IDEA现在也有对应的版本旗舰版和社区版了,而且使用更贴心,更给力,为什么还要选一个难用的要死的东西呢? 最近要开发一个Java Web项目,所 ...
- Jmeter----读取excel表中的数据
Jmeter 读取excel数据使用的方法是使用CSV Data Set Config参数化,之后使用BeanShell Sampler来读取excel表中的数据 第一步.查看所需的接口都要哪些字段和 ...
- JavaScript性能优化【转载】
你愿意为打开一个网页等待多长时间?我一秒也不愿意等.但是事实上大多数网站在响应速度方面都让人失望.现在越来越多的人开始建立自己的网站,博客,你的网页响应速度如何呢?在这篇文章中我们来介绍一下提高网页性 ...
- Java Control Statements
Java Control Statements Java For Loop public class ForExample1 { public static void main(String[] ar ...
- JavaScript 闭包(随笔)
闭包,伟大的闭包.... 先看看百科对百度的定义是什么样的. 百科说:闭包是指可以包含自由(未绑定到特定对象)变量的代码块:这些变量不是在这个代码块内或者任何全局上下文中定义的,而是在定义代码块的环境 ...
- PTA L2-004 这是二叉搜索树吗?-判断是否是对一棵二叉搜索树或其镜像进行前序遍历的结果 团体程序设计天梯赛-练习集
L2-004 这是二叉搜索树吗? (25 分) 一棵二叉搜索树可被递归地定义为具有下列性质的二叉树:对于任一结点, 其左子树中所有结点的键值小于该结点的键值: 其右子树中所有结点的键值大于等于该结 ...
- Storm基本概念以及Topology的并发度
Spouts,流的源头 Spout是Storm里面特有的名词,Stream的源头,通常是从外部数据源读取tuples,并emit到topology Spout可以同时emit多个tupic strea ...