废话不多说,直接上!!!!
先准备两个实体类
第一个
订单详细实体类
TbOrderEntity
/**
* 用户ID
*/
private Long userid;
/**
* 商品ID
*/
private Long goodsId;
/**
* 商店ID
*/
private Long shopid;
/**
* 店铺名称
*/
private String shopname;
/**
* 商品购买数量
*/
private Integer goodsBuynum;
/**
* 商品图片地址
*/
private String goodsImg;
/**
* 商品名称
*/
private String goodsName;
/**
* 商品价格
*/
private BigDecimal goodsPrice;
/**
* 地址
*/
private String address;
/**
* 下单日期
*/
private Date orderdate;
/**
* 订单号
*/
private Long ordernumber;
/**
* 付款状态
*/
private Integer status;
/**
* 修改者
*/
private String regenerator;
/**
* 修改时间
*/
private Date updateTime;
/**
* 租户编码
*/
private Long tenantCode;
/**
* 备注
*/
private String remark;
第二个
TEntity
/**
* 商家idname
*/
private String shopid;
/**
* 商家名称
*/
private String shopname;
/**
* 用户id
*/
private Long userid;
/**
* 商品id
*/
private Long goodsid;
/**
* 商品信息
*/
private List<TbOrderEntity> orderEntities;
/**
* 备注
*/
private String remark;
/**
* 创建者
*/
private Long creator;
/**
* 创建时间
*/
private Date createDate;
/**
* 修改者
*/
private String regenerator;
/**
* 修改时间
*/
private Date updateDate;
/**
* 租户编码
*/
private Long tenantCode;
后面是控制层(controller)
TbOrderController
@Autowired
private TbOrderService tbOrderService;
@GetMapping("/uid/{uid}")
@ApiOperation("根据客户Id信息")
public Result<List<TEntity>> queryuid(@PathVariable("uid") Long uid){
List<TEntity> data = tbOrderService.query(uid);
return new Result<List<TEntity>>().ok(data);
}
这里就写一个查询方法。。。。。
服务层接口(service)
TbOrderService
List<TEntity> query(Long uid);
服务类
TbOrderServiceImpl
//根据uid搜索
@Override
public List<TEntity> query(Long uid) {
List<TEntity> entity = tbOrderDao.selectuid(uid);
return ConvertUtils.sourceToTarget(entity, TEntity.class);
}
Dao层
TbOrderDao
List<TEntity> selectuid(Long uid);
Mapper层
最关键的地方就在这!!!!!
<resultMap type="com.zx.entity.TEntity" id="TbCartMap">
<id column="shopid" property="shopid"/>
<result column="shopname" property="shopname"/>
<collection property="orderEntities" ofType="com.zx.entity.TbOrderEntity">
<result property="id" column="id"/>
<result property="userid" column="userid"/>
<result property="goodsId" column="goods_id"/>
<result property="shopid" column="shopId"/>
<result property="shopname" column="shopName"/>
<result property="goodsBuynum" column="goods_buynum"/>
<result property="goodsImg" column="goods_img"/>
<result property="goodsName" column="goods_name"/>
<result property="goodsPrice" column="goods_price"/>
<result property="address" column="address"/>
<result property="orderdate" column="orderDate"/>
<result property="ordernumber" column="orderNumber"/>
<result property="status" column="status"/>
<result property="creator" column="creator"/>
<result property="createDate" column="create_date"/>
<result property="regenerator" column="regenerator"/>
<result property="updateTime" column="update_time"/>
<result property="tenantCode" column="tenant_code"/>
<result property="remark" column="remark"/>
</collection>
</resultMap>
<select id="selectuid" parameterType="Long" resultMap="TbCartMap">
select
tr.id,
tr.shopId,
tr.goods_id,
tr.shopName,
tr.goods_buynum,
tr.goods_img,
tr.goods_name,
tr.goods_price,
tr.address,
tr.orderDate,
tr.orderNumber,
tr.status
from tb_order tr
where tr.userid=#{userid}
order by tr.goods_id
</select>
查询结果:
{
"code": 0,
"msg": "success",
"data": [
{
"id": null,
"creator": null,
"createDate": null,
"tenantCode": null,
"shopid": "1",
"shopname": "雨润超市",
"userid": null,
"goodsid": null,
"orderEntities": [
{
"id": "1",
"creator": null,
"createDate": null,
"tenantCode": null,
"userid": null,
"goodsId": "1",
"shopid": "1",
"shopname": "雨润超市",
"goodsBuynum": 111,
"goodsImg": "http",
"goodsName": "敌敌畏",
"goodsPrice": 1000,
"address": "江苏",
"orderdate": "2019-11-28 15:26:11",
"ordernumber": "1",
"status": 1,
"regenerator": null,
"updateTime": null,
"remark": null
},
{
"id": "5",
"creator": null,
"createDate": null,
"tenantCode": null,
"userid": null,
"goodsId": "3",
"shopid": "1",
"shopname": "雨润超市",
"goodsBuynum": 111,
"goodsImg": "",
"goodsName": null,
"goodsPrice": null,
"address": null,
"orderdate": null,
"ordernumber": null,
"status": null,
"regenerator": null,
"updateTime": null,
"remark": null
}
],
"remark": null,
"regenerator": null,
"updateDate": null
},
{
"id": null,
"creator": null,
"createDate": null,
"tenantCode": null,
"shopid": "2",
"shopname": "苏果超市",
"userid": null,
"goodsid": null,
"orderEntities": [
{
"id": "4",
"creator": null,
"createDate": null,
"tenantCode": null,
"userid": null,
"goodsId": "2",
"shopid": "2",
"shopname": "苏果超市",
"goodsBuynum": 222,
"goodsImg": "http",
"goodsName": "化肥",
"goodsPrice": 3000,
"address": "河南",
"orderdate": "2019-11-29 16:14:29",
"ordernumber": "1",
"status": 1,
"regenerator": null,
"updateTime": null,
"remark": null
}
],
"remark": null,
"regenerator": null,
"updateDate": null
}
]
}
版权声明:本文为weixin_45260280原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。