实战SSM_O2O商铺_09【商铺注册】DTO之ShopExecution的实现
【摘要】
文章目录
DTO概述枚举类DTO类ShopExecutionGithub地址
DTO概述
Data Transfer Object,数据传送对象 .
DTO是一个普通的Java类,它...
DTO概述
Data Transfer Object,数据传送对象 .
DTO是一个普通的Java类,它封装了要传送的批量的数据。当客户端需要读取服务器端的数据的时候,服务器端将数据封装在DTO中,这样客户端就可以在一个网络调用中获得它需要的所有数据。
Shop实体类包含了Shop的基本属性,但是在前端操作时,我们希望可以返回操作的结果等信息,这个时候Shop实体类就不能满足需求了,我们将操作结果和Shop等信息统一放到DTO中处理,即可满足当前的需求。
枚举类
package com.artisan.o2o.enums;
/**
*
*
* @ClassName: ShopStateEnum
*
* @Description: 使用枚举表述常量数据字典
*
* @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:私有构造函数,禁止外部初始化改变定义的常量
*
* @param state
* @param stateInfo
*/
private ShopStateEnum(int state, String stateInfo) {
this.state = state;
this.stateInfo = stateInfo;
}
/**
*
*
* @Title: getState
*
* @Description: 仅设置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;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
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中还要包含操作商铺的返回结果,单个的实体类无法满足,所以封装到dto中,便于操作
*
* @author: Mr.Yang
*
* @date: 2018年5月19日 下午2:50:29
*/
public class ShopExecution {
/**
* 操作结果状态
*/
private int state ;
/**
* 操作结果状态说明
*/
private String stateInfo;
/**
* 店铺数量
*/
private int count;
/**
* 店铺 (增删改店铺的时候用)
*/
private Shop shop;
/**
* 店铺集合 (查询店铺列表的时候用)
*/
private List<Shop> shopList;
/**
*
*
* @Title:ShopExecution
*
* @Description: 构造函数,店铺操作失败的时候使用的构造函数
*
* @param shopStateEnum
*/
public ShopExecution(ShopStateEnum shopStateEnum) {
this.state = shopStateEnum.getState();
this.stateInfo = shopStateEnum.getStateInfo();
}
/**
*
*
* @Title:ShopExecution
*
* @Description:构造函数,店铺操作成功的时候使用的构造函数
*
* @param stateEnum
* @param shop
*/
public ShopExecution(ShopStateEnum stateEnum, Shop shop) {
this.state = stateEnum.getState();
this.stateInfo = stateEnum.getStateInfo();
this.shop = shop;
}
/**
*
*
* @Title:ShopExecution
*
* @Description:构造函数,店铺操作成功的时候使用的构造函数
*
* @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;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
Github地址
代码地址: https://github.com/yangshangwei/o2o
文章来源: artisan.blog.csdn.net,作者:小小工匠,版权归原作者所有,如需转载,请联系作者。
原文链接:artisan.blog.csdn.net/article/details/80387446
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)