实战SSM_O2O商铺_09【商铺注册】DTO之ShopExecution的实现
生活随笔
收集整理的這篇文章主要介紹了
实战SSM_O2O商铺_09【商铺注册】DTO之ShopExecution的实现
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- DTO概述
- 枚舉類
- DTO類ShopExecution
- Github地址
DTO概述
Data Transfer Object,數(shù)據(jù)傳送對象 .
DTO是一個(gè)普通的Java類,它封裝了要傳送的批量的數(shù)據(jù)。當(dāng)客戶端需要讀取服務(wù)器端的數(shù)據(jù)的時(shí)候,服務(wù)器端將數(shù)據(jù)封裝在DTO中,這樣客戶端就可以在一個(gè)網(wǎng)絡(luò)調(diào)用中獲得它需要的所有數(shù)據(jù)。
Shop實(shí)體類包含了Shop的基本屬性,但是在前端操作時(shí),我們希望可以返回操作的結(jié)果等信息,這個(gè)時(shí)候Shop實(shí)體類就不能滿足需求了,我們將操作結(jié)果和Shop等信息統(tǒng)一放到DTO中處理,即可滿足當(dāng)前的需求。
枚舉類
package com.artisan.o2o.enums;/*** * * @ClassName: ShopStateEnum* * @Description: 使用枚舉表述常量數(shù)據(jù)字典* * @author: Mr.Yang* * @date: 2018年5月19日 下午3:00:31*/ public enum ShopStateEnum {CHECK(0, "審核中"), OFFLINE(-1, "非法店鋪"), SUCCESS(1, "操作成功"), PASS(2, "審核通過"), INNER_ERROR(-1001, "操作失敗"), NULL_SHOPID(-1002, "ShopId為空"), NULL_SHOP_INFO(-1003, "傳入了空的信息");private int state;private String stateInfo;/*** * * @Title:ShopStateEnum* * @Description:私有構(gòu)造函數(shù),禁止外部初始化改變定義的常量* * @param state* @param stateInfo*/private ShopStateEnum(int state, String stateInfo) {this.state = state;this.stateInfo = stateInfo;}/*** * * @Title: getState* * @Description: 僅設(shè)置get方法,禁用set* * @return* * @return: int*/public int getState() {return state;}public String getStateInfo() {return stateInfo;}/*** * * @Title: stateOf* * @Description: 定義換成pulic static 暴漏給外部,通過state獲取ShopStateEnum* * values()獲取全部的enum常量* * @param state* * @return: ShopStateEnum*/public static ShopStateEnum stateOf(int state) {for (ShopStateEnum stateEnum : values()) {if(stateEnum.getState() == state){return stateEnum;}}return null;}}DTO類ShopExecution
package com.artisan.o2o.dto;import java.util.List;import com.artisan.o2o.entity.Shop; import com.artisan.o2o.enums.ShopStateEnum;/*** * * @ClassName: ShopExecution* * @Description: DTO中還要包含操作商鋪的返回結(jié)果,單個(gè)的實(shí)體類無法滿足,所以封裝到dto中,便于操作* * @author: Mr.Yang* * @date: 2018年5月19日 下午2:50:29*/ public class ShopExecution {/*** 操作結(jié)果狀態(tài)*/private int state ;/*** 操作結(jié)果狀態(tài)說明*/private String stateInfo;/*** 店鋪數(shù)量*/private int count;/*** 店鋪 (增刪改店鋪的時(shí)候用)*/private Shop shop;/*** 店鋪集合 (查詢店鋪列表的時(shí)候用)*/private List<Shop> shopList;/*** * * @Title:ShopExecution* * @Description: 構(gòu)造函數(shù),店鋪操作失敗的時(shí)候使用的構(gòu)造函數(shù)* * @param shopStateEnum*/public ShopExecution(ShopStateEnum shopStateEnum) {this.state = shopStateEnum.getState();this.stateInfo = shopStateEnum.getStateInfo();}/*** * * @Title:ShopExecution* * @Description:構(gòu)造函數(shù),店鋪操作成功的時(shí)候使用的構(gòu)造函數(shù)* * @param stateEnum* @param shop*/public ShopExecution(ShopStateEnum stateEnum, Shop shop) {this.state = stateEnum.getState();this.stateInfo = stateEnum.getStateInfo();this.shop = shop;}/*** * * @Title:ShopExecution* * @Description:構(gòu)造函數(shù),店鋪操作成功的時(shí)候使用的構(gòu)造函數(shù)* * @param stateEnum* @param shopList*/public ShopExecution(ShopStateEnum stateEnum, List<Shop> shopList) {this.state = stateEnum.getState();this.stateInfo = stateEnum.getStateInfo();this.shopList = shopList;}/*** * setter/getter* */public int getState() {return state;}public void setState(int state) {this.state = state;}public String getStateInfo() {return stateInfo;}public void setStateInfo(String stateInfo) {this.stateInfo = stateInfo;}public int getCount() {return count;}public void setCount(int count) {this.count = count;}public Shop getShop() {return shop;}public void setShop(Shop shop) {this.shop = shop;}public List<Shop> getShopList() {return shopList;}public void setShopList(List<Shop> shopList) {this.shopList = shopList;}}Github地址
代碼地址: https://github.com/yangshangwei/o2o
總結(jié)
以上是生活随笔為你收集整理的实战SSM_O2O商铺_09【商铺注册】DTO之ShopExecution的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实战SSM_O2O商铺_08【商铺注册】
- 下一篇: 实战SSM_O2O商铺_10【商铺注册】