飞道的博客

JAVA3个数据层(pojo,dto,vo)、dao层、services层、controller层解释

372人阅读  评论(0)

3个数据层(pojo,dto,vo)

POJO(也叫Entiy、model):每一个字段,与数据库中表字段相对应,表字段"_"对应java对象的"驼峰"


   
  1. package com.xiaolong.pojo;
  2. import io.swagger.annotations.ApiModelProperty;
  3. import java.io.Serializable;
  4. import java.math.BigDecimal;
  5. import java.util.Date;
  6. public class OmsOrder implements Serializable {
  7.     @ApiModelProperty(value =  "订单id")
  8.     private Long id;
  9.     private Long memberId;
  10.     private Long couponId;
  11.     @ApiModelProperty(value =  "订单编号")
  12.     private String orderSn;
  13.     @ApiModelProperty(value =  "提交时间")
  14.     private Date createTime;
  15.     @ApiModelProperty(value =  "用户帐号")
  16.     private String memberUsername;
  17.     @ApiModelProperty(value =  "订单总金额")
  18.     private BigDecimal totalAmount;
  19.     public Long getId() {
  20.          return id;
  21.     }
  22.     public void setId(Long id) {
  23.         this.id = id;
  24.     }
  25.     public Long getMemberId() {
  26.          return memberId;
  27.     }
  28.     public void setMemberId(Long memberId) {
  29.         this.memberId = memberId;
  30.     }
  31.     public Long getCouponId() {
  32.          return couponId;
  33.     }
  34.     public void setCouponId(Long couponId) {
  35.         this.couponId = couponId;
  36.     }
  37.     public String getOrderSn() {
  38.          return orderSn;
  39.     }
  40.     public void setOrderSn(String orderSn) {
  41.         this.orderSn = orderSn;
  42.     }
  43.     public Date getCreateTime() {
  44.          return createTime;
  45.     }
  46.     public void setCreateTime(Date createTime) {
  47.         this.createTime = createTime;
  48.     }
  49.     public String getMemberUsername() {
  50.          return memberUsername;
  51.     }
  52.     public void setMemberUsername(String memberUsername) {
  53.         this.memberUsername = memberUsername;
  54.     }
  55.     public BigDecimal getTotalAmount() {
  56.          return totalAmount;
  57.     }
  58.     public void setTotalAmount(BigDecimal totalAmount) {
  59.         this.totalAmount = totalAmount;
  60.     }
  61.     public BigDecimal getPayAmount() {
  62.          return payAmount;
  63.     }
  64.     public void setPayAmount(BigDecimal payAmount) {
  65.         this.payAmount = payAmount;
  66.     }
  67.     @Override
  68.     public String toString() {
  69.         StringBuilder sb =  new StringBuilder();
  70.         sb. append(getClass().getSimpleName());
  71.         sb. append( " [");
  72.         sb. append( "Hash = "). append(hashCode());
  73.         sb. append( ", id="). append(id);
  74.         sb. append( ", memberId="). append(memberId);
  75.         sb. append( ", couponId="). append(couponId);
  76.         sb. append( ", orderSn="). append(orderSn);
  77.         sb. append( ", createTime="). append(createTime);
  78.         sb. append( ", memberUsername="). append(memberUsername);
  79.         sb. append( ", totalAmount="). append(totalAmount);
  80.         sb. append( "]");
  81.          return sb.toString();
  82.     }
  83. }

DTO(也叫param,表单用):数据传输对象


   
  1. package com.xiaolong.dto;
  2. import io.swagger.annotations.ApiModelProperty;
  3. import lombok.Getter;
  4. import lombok.Setter;
  5. import javax.validation.constraints.Email;
  6. import javax.validation.constraints.NotEmpty;
  7. @Getter
  8. @Setter
  9. public class UmsAdminParam {
  10.     @NotEmpty
  11.     @ApiModelProperty(value =  "用户名", required =  true)
  12.     private String username;
  13.     @NotEmpty
  14.     @ApiModelProperty(value =  "密码", required =  true)
  15.     private String password;
  16.     @ApiModelProperty(value =  "用户头像")
  17.     private String icon;
  18.     @Email
  19.     @ApiModelProperty(value =  "邮箱")
  20.     private String email;
  21.     @ApiModelProperty(value =  "用户昵称")
  22.     private String nickName;
  23.     @ApiModelProperty(value =  "备注")
  24.     private String note;
  25. }

VO(前端调用后端接口或者请求后端,后端返回给前端的响应数据用,如json字符串,有的项目VO和DTO是不区分,中大型项目都是区分开的)


   
  1. package com.xiaolong.vo;
  2. import io.swagger.annotations.ApiModelProperty;
  3. import lombok.Data;
  4. import lombok.EqualsAndHashCode;
  5. @Data
  6. @EqualsAndHashCode(callSuper =  false)
  7. public class OssCallbackVo {
  8.     @ApiModelProperty( "文件名称")
  9.     private String filename;
  10.     @ApiModelProperty( "文件大小")
  11.     private String size;
  12.     @ApiModelProperty( "文件的mimeType")
  13.     private String mimeType;
  14.     @ApiModelProperty( "图片文件的宽")
  15.     private String width;
  16.     @ApiModelProperty( "图片文件的高")
  17.     private String height;
  18. }

Dao层(dao也叫做mapper,mapper.xml实现Dao)

dao或者mapper接口,不需要你实现,mybatis替你实现了接口,你只需要定义xml之后mybatis就帮你实现了dao方法,当然你也可以用注解的方式,就相当于你只是定义了一个抽象的方法,有下面工人自动帮你做具体的事情了


   
  1. public  interface OmsOrderDao {
  2.      /**
  3.      * 条件查询订单
  4.      */
  5.     List<OmsOrder> getList(@Param( "queryParam") OmsOrderQueryParam queryParam);
  6.      /**
  7.      * 批量发货
  8.      */
  9.      int delivery(@Param( "list") List<OmsOrderDeliveryParam> deliveryParamList);
  10.      /**
  11.      * 获取订单详情
  12.      */
  13.     OmsOrderDetail getDetail(@Param( "id") Long id);
  14. }

   
  1. <?xml version= "1.0" encoding= "UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC  "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace= "com.xiaolong.dao.OmsOrderDao">
  4.     <resultMap id= "orderDetailResultMap"  type= "com.xiaolong.dto.OmsOrderDetail" extends= "com.xiaolong.mapper.OmsOrderMapper.BaseResultMap">
  5.         <collection property= "orderItemList" resultMap= "com.xiaolong.mapper.OmsOrderItemMapper.BaseResultMap" columnPrefix= "item_"/>
  6.         <collection property= "historyList" resultMap= "com.xiaolong.mapper.OmsOrderOperateHistoryMapper.BaseResultMap" columnPrefix= "history_"/>
  7.     </resultMap>
  8.     < select id= "getList" resultMap= "com.xiaolong.mapper.OmsOrderMapper.BaseResultMap">
  9.         SELECT *
  10.         FROM
  11.         oms_order
  12.         WHERE
  13.         delete_status =  0
  14.         < if test= "queryParam.orderSn!=null and queryParam.orderSn!=''">
  15.             AND order_sn = #{queryParam.orderSn}
  16.         </ if>
  17.         < if test= "queryParam.status!=null">
  18.             AND  `status` = #{queryParam.status}
  19.         </ if>
  20.         < if test= "queryParam.sourceType!=null">
  21.             AND source_type = #{queryParam.sourceType}
  22.         </ if>
  23.         < if test= "queryParam.orderType!=null">
  24.             AND order_type = #{queryParam.orderType}
  25.         </ if>
  26.         < if test= "queryParam.createTime!=null and queryParam.createTime!=''">
  27.             AND create_time LIKE concat(#{queryParam.createTime}, "%")
  28.         </ if>
  29.         < if test= "queryParam.receiverKeyword!=null and queryParam.receiverKeyword!=''">
  30.             AND (
  31.             receiver_name LIKE concat( "%",#{queryParam.receiverKeyword}, "%")
  32.             OR receiver_phone LIKE concat( "%",#{queryParam.receiverKeyword}, "%")
  33.             )
  34.         </ if>
  35.     </ select>
  36.     <update id= "delivery">
  37.         UPDATE oms_order
  38.         SET
  39.         delivery_sn = CASE id
  40.         <foreach collection= "list" item= "item">
  41.             WHEN #{item.orderId} THEN #{item.deliverySn}
  42.         </foreach>
  43.         END,
  44.         delivery_company = CASE id
  45.         <foreach collection= "list" item= "item">
  46.             WHEN #{item.orderId} THEN #{item.deliveryCompany}
  47.         </foreach>
  48.         END,
  49.         delivery_time = CASE id
  50.         <foreach collection= "list" item= "item">
  51.             WHEN #{item.orderId} THEN now()
  52.         </foreach>
  53.         END,
  54.          `status` = CASE id
  55.         <foreach collection= "list" item= "item">
  56.             WHEN #{item.orderId} THEN  2
  57.         </foreach>
  58.         END
  59.         WHERE
  60.         id IN
  61.         <foreach collection= "list" item= "item" separator= "," open= "("  close= ")">
  62.             #{item.orderId}
  63.         </foreach>
  64.         AND  `status` =  1
  65.     </update>
  66.     < select id= "getDetail" resultMap= "orderDetailResultMap">
  67.         SELECT o.*,
  68.             oi.id item_id,
  69.             oi.product_id item_product_id,
  70.             oi.product_sn item_product_sn,
  71.             oi.product_pic item_product_pic,
  72.             oi.product_name item_product_name,
  73.             oi.product_brand item_product_brand,
  74.             oi.product_price item_product_price,
  75.             oi.product_quantity item_product_quantity,
  76.             oi.product_attr item_product_attr,
  77.             oh.id history_id,
  78.             oh.operate_man history_operate_man,
  79.             oh.create_time history_create_time,
  80.             oh.order_status history_order_status,
  81.             oh.note history_note
  82.         FROM
  83.             oms_order o
  84.             LEFT JOIN oms_order_item oi ON o.id = oi.order_id
  85.             LEFT JOIN oms_order_operate_history oh ON o.id = oh.order_id
  86.         WHERE
  87.             o.id = #{id}
  88.         ORDER BY oi.id ASC,oh.create_time DESC
  89.     </ select>
  90. </mapper>

Service层

接口service层,实现方法serviceImpl,调用dao方法实现功能,最后以便Conttroller调用

Controller层

一键三连,感谢!


转载:https://blog.csdn.net/weixin_40562504/article/details/109634973
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场