3个数据层(pojo,dto,vo)
POJO(也叫Entiy、model):每一个字段,与数据库中表字段相对应,表字段"_"对应java对象的"驼峰"
-
package com.xiaolong.pojo;
-
-
import io.swagger.annotations.ApiModelProperty;
-
import java.io.Serializable;
-
import java.math.BigDecimal;
-
import java.util.Date;
-
-
public class OmsOrder implements Serializable {
-
@ApiModelProperty(value =
"订单id")
-
private Long id;
-
-
private Long memberId;
-
-
private Long couponId;
-
-
@ApiModelProperty(value =
"订单编号")
-
private String orderSn;
-
-
@ApiModelProperty(value =
"提交时间")
-
private Date createTime;
-
-
@ApiModelProperty(value =
"用户帐号")
-
private String memberUsername;
-
-
@ApiModelProperty(value =
"订单总金额")
-
private BigDecimal totalAmount;
-
-
public Long getId() {
-
return id;
-
}
-
-
public void setId(Long id) {
-
this.id = id;
-
}
-
-
public Long getMemberId() {
-
return memberId;
-
}
-
-
public void setMemberId(Long memberId) {
-
this.memberId = memberId;
-
}
-
-
public Long getCouponId() {
-
return couponId;
-
}
-
-
public void setCouponId(Long couponId) {
-
this.couponId = couponId;
-
}
-
-
public String getOrderSn() {
-
return orderSn;
-
}
-
-
public void setOrderSn(String orderSn) {
-
this.orderSn = orderSn;
-
}
-
-
public Date getCreateTime() {
-
return createTime;
-
}
-
-
public void setCreateTime(Date createTime) {
-
this.createTime = createTime;
-
}
-
-
public String getMemberUsername() {
-
return memberUsername;
-
}
-
-
public void setMemberUsername(String memberUsername) {
-
this.memberUsername = memberUsername;
-
}
-
-
public BigDecimal getTotalAmount() {
-
return totalAmount;
-
}
-
-
public void setTotalAmount(BigDecimal totalAmount) {
-
this.totalAmount = totalAmount;
-
}
-
-
public BigDecimal getPayAmount() {
-
return payAmount;
-
}
-
-
public void setPayAmount(BigDecimal payAmount) {
-
this.payAmount = payAmount;
-
}
-
-
@Override
-
public String toString() {
-
StringBuilder sb =
new StringBuilder();
-
sb.
append(getClass().getSimpleName());
-
sb.
append(
" [");
-
sb.
append(
"Hash = ").
append(hashCode());
-
sb.
append(
", id=").
append(id);
-
sb.
append(
", memberId=").
append(memberId);
-
sb.
append(
", couponId=").
append(couponId);
-
sb.
append(
", orderSn=").
append(orderSn);
-
sb.
append(
", createTime=").
append(createTime);
-
sb.
append(
", memberUsername=").
append(memberUsername);
-
sb.
append(
", totalAmount=").
append(totalAmount);
-
sb.
append(
"]");
-
return sb.toString();
-
}
-
}
DTO(也叫param,表单用):数据传输对象
-
package com.xiaolong.dto;
-
-
import io.swagger.annotations.ApiModelProperty;
-
import lombok.Getter;
-
import lombok.Setter;
-
-
import javax.validation.constraints.Email;
-
import javax.validation.constraints.NotEmpty;
-
@Getter
-
@Setter
-
public class UmsAdminParam {
-
@NotEmpty
-
@ApiModelProperty(value =
"用户名", required =
true)
-
private String username;
-
@NotEmpty
-
@ApiModelProperty(value =
"密码", required =
true)
-
private String password;
-
@ApiModelProperty(value =
"用户头像")
-
private String icon;
-
@Email
-
@ApiModelProperty(value =
"邮箱")
-
private String email;
-
@ApiModelProperty(value =
"用户昵称")
-
private String nickName;
-
@ApiModelProperty(value =
"备注")
-
private String note;
-
}
VO(前端调用后端接口或者请求后端,后端返回给前端的响应数据用,如json字符串,有的项目VO和DTO是不区分,中大型项目都是区分开的)
-
package com.xiaolong.vo;
-
-
import io.swagger.annotations.ApiModelProperty;
-
import lombok.Data;
-
import lombok.EqualsAndHashCode;
-
@Data
-
@EqualsAndHashCode(callSuper =
false)
-
public class OssCallbackVo {
-
@ApiModelProperty(
"文件名称")
-
private String filename;
-
@ApiModelProperty(
"文件大小")
-
private String size;
-
@ApiModelProperty(
"文件的mimeType")
-
private String mimeType;
-
@ApiModelProperty(
"图片文件的宽")
-
private String width;
-
@ApiModelProperty(
"图片文件的高")
-
private String height;
-
}
Dao层(dao也叫做mapper,mapper.xml实现Dao)
dao或者mapper接口,不需要你实现,mybatis替你实现了接口,你只需要定义xml之后mybatis就帮你实现了dao方法,当然你也可以用注解的方式,就相当于你只是定义了一个抽象的方法,有下面工人自动帮你做具体的事情了
-
public
interface OmsOrderDao {
-
/**
-
* 条件查询订单
-
*/
-
List<OmsOrder> getList(@Param(
"queryParam") OmsOrderQueryParam queryParam);
-
-
/**
-
* 批量发货
-
*/
-
int delivery(@Param(
"list") List<OmsOrderDeliveryParam> deliveryParamList);
-
-
/**
-
* 获取订单详情
-
*/
-
OmsOrderDetail getDetail(@Param(
"id") Long id);
-
}
-
<?xml version=
"1.0" encoding=
"UTF-8"?>
-
<!DOCTYPE mapper PUBLIC
"-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
<mapper namespace=
"com.xiaolong.dao.OmsOrderDao">
-
<resultMap id=
"orderDetailResultMap"
type=
"com.xiaolong.dto.OmsOrderDetail" extends=
"com.xiaolong.mapper.OmsOrderMapper.BaseResultMap">
-
<collection property=
"orderItemList" resultMap=
"com.xiaolong.mapper.OmsOrderItemMapper.BaseResultMap" columnPrefix=
"item_"/>
-
<collection property=
"historyList" resultMap=
"com.xiaolong.mapper.OmsOrderOperateHistoryMapper.BaseResultMap" columnPrefix=
"history_"/>
-
</resultMap>
-
<
select id=
"getList" resultMap=
"com.xiaolong.mapper.OmsOrderMapper.BaseResultMap">
-
SELECT *
-
FROM
-
oms_order
-
WHERE
-
delete_status =
0
-
<
if test=
"queryParam.orderSn!=null and queryParam.orderSn!=''">
-
AND order_sn = #{queryParam.orderSn}
-
</
if>
-
<
if test=
"queryParam.status!=null">
-
AND
`status` = #{queryParam.status}
-
</
if>
-
<
if test=
"queryParam.sourceType!=null">
-
AND source_type = #{queryParam.sourceType}
-
</
if>
-
<
if test=
"queryParam.orderType!=null">
-
AND order_type = #{queryParam.orderType}
-
</
if>
-
<
if test=
"queryParam.createTime!=null and queryParam.createTime!=''">
-
AND create_time LIKE concat(#{queryParam.createTime},
"%")
-
</
if>
-
<
if test=
"queryParam.receiverKeyword!=null and queryParam.receiverKeyword!=''">
-
AND (
-
receiver_name LIKE concat(
"%",#{queryParam.receiverKeyword},
"%")
-
OR receiver_phone LIKE concat(
"%",#{queryParam.receiverKeyword},
"%")
-
)
-
</
if>
-
</
select>
-
<update id=
"delivery">
-
UPDATE oms_order
-
SET
-
delivery_sn = CASE id
-
<foreach collection=
"list" item=
"item">
-
WHEN #{item.orderId} THEN #{item.deliverySn}
-
</foreach>
-
END,
-
delivery_company = CASE id
-
<foreach collection=
"list" item=
"item">
-
WHEN #{item.orderId} THEN #{item.deliveryCompany}
-
</foreach>
-
END,
-
delivery_time = CASE id
-
<foreach collection=
"list" item=
"item">
-
WHEN #{item.orderId} THEN now()
-
</foreach>
-
END,
-
`status` = CASE id
-
<foreach collection=
"list" item=
"item">
-
WHEN #{item.orderId} THEN
2
-
</foreach>
-
END
-
WHERE
-
id IN
-
<foreach collection=
"list" item=
"item" separator=
"," open=
"("
close=
")">
-
#{item.orderId}
-
</foreach>
-
AND
`status` =
1
-
</update>
-
<
select id=
"getDetail" resultMap=
"orderDetailResultMap">
-
SELECT o.*,
-
oi.id item_id,
-
oi.product_id item_product_id,
-
oi.product_sn item_product_sn,
-
oi.product_pic item_product_pic,
-
oi.product_name item_product_name,
-
oi.product_brand item_product_brand,
-
oi.product_price item_product_price,
-
oi.product_quantity item_product_quantity,
-
oi.product_attr item_product_attr,
-
oh.id history_id,
-
oh.operate_man history_operate_man,
-
oh.create_time history_create_time,
-
oh.order_status history_order_status,
-
oh.note history_note
-
FROM
-
oms_order o
-
LEFT JOIN oms_order_item oi ON o.id = oi.order_id
-
LEFT JOIN oms_order_operate_history oh ON o.id = oh.order_id
-
WHERE
-
o.id = #{id}
-
ORDER BY oi.id ASC,oh.create_time DESC
-
</
select>
-
</mapper>
Service层
接口service层,实现方法serviceImpl,调用dao方法实现功能,最后以便Conttroller调用
Controller层
一键三连,感谢!
转载:https://blog.csdn.net/weixin_40562504/article/details/109634973
查看评论