shop--6.店铺注册--Dto之ShopExecution的实现

在实现Service层之前 需要考虑

在操作Shop时候 会有个操作状态(成功或者失败) 并且需要返回给Controller层

 

创建Enum类ShopStateEnum

用来表示店铺的状态

public enum ShopStateEnum {
        CHECK(0,"审核中"),OFFLINE(-1,"非法店铺"),SUCCESS(1,"操作成功")
        ,PASS(2,"通过认证"),INNER_ERROR(-1001,"内部系统错误"),
        NULL_SHOPID(-1002,"ShopId为空"),NULL_SHOP(-1003,"店铺信息为空");
        private int state;
        private String stateInfo;
        
        //构造器是私有的 不希望第三方来改Enum的值
        private ShopStateEnum(int state,String stateInfo) {
            this.state = state;
            this.stateInfo = stateInfo;
        }
        /**
         * 依据传入的state返回相应的enum的值
         *
         */
        public static ShopStateEnum stateOf(int state) {
            for (ShopStateEnum stateEnum : values()) {
                if (stateEnum.getState() == state) {
                    return stateEnum;
                }
            }
            return null;

        }
        public int getState() {
            return state;
        }

        public String getStateInfo() {
            return stateInfo;
        }

        
    }

 

dto中ShopExection类的创建

包含店铺的状态信息 (枚举类型)

店铺的数量

店铺的实体类

public class ShopExecution {
    //结果状态
    private int state;
    
    //状态标识
    private String stateInfo;
    
    //店铺数量
    private int count;
    
    //操作的shop(增删改店铺的时候用到)
    private Shop shop;
    
    //shop列表(查询店铺列表的时候使用)
    private List shopList;
    
    public ShopExecution() {
        
    }
    
    //店铺操作失败的时候使用的构造器
    public ShopExecution(ShopStateEnum stateEnum) {
        this.state = stateEnum.getState();
        this.stateInfo = stateEnum.getStateInfo();
    }
    
    //店铺操作成功的时候使用的构造器  店铺操作成功才能返回Shop信息
    public ShopExecution(ShopStateEnum stateEnum,Shop shop) {
        this.state = stateEnum.getState();
        this.stateInfo = stateEnum.getStateInfo();
        this.shop = shop;
    }
    
    //店铺操作成功的时候使用的构造器
        public ShopExecution(ShopStateEnum stateEnum,List shopList) {
            this.state = stateEnum.getState();
            this.stateInfo = stateEnum.getStateInfo();
            this.shopList = shopList;
        }

        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 getShopList() {
            return shopList;
        }

        public void setShopList(List shopList) {
            this.shopList = shopList;
        }
        
    
}

 

转载于:https://www.cnblogs.com/windbag7/p/9342733.html

你可能感兴趣的:(shop--6.店铺注册--Dto之ShopExecution的实现)