shop--8.商品类别--辅助工具
ProductCategoryEnum
public enum ProductCategoryEnum { SUCCESS(1, "创建成功"), INNER_ERROR(-1001, "操作失败"), EMPTY_LIST(-1002, "添加数少于1"); private int state; private String stateInfo; private ProductCategoryEnum(int state, String stateInfo) { this.state = state; this.stateInfo = stateInfo; } public int getState() { return state; } public String getStateInfo() { return stateInfo; } /** * 依据传入的state返回相应的enum值 */ public static ProductCategoryEnum stateof(int state){ for(ProductCategoryEnum s : values()){ if(s.getState() == state){ return s; } } return null; } }
ProductCategoryException
public class ProductCategoryException extends RuntimeException{ private static final long serialVersionUID = 3278462788156006845L; public ProductCategoryException(String message) { super( message ); } }
ProductCategoryExecution
public class ProductCategoryExecution { private int state; private String stateInfo; private List<ProductCategory> productCategoryList; public ProductCategoryExecution() { } //操作失败时,使用的构造器 public ProductCategoryExecution(ProductCategoryEnum stateEnum ){ this.state = stateEnum.getState(); this.stateInfo = stateEnum.getStateInfo(); } //操作成功时,使用的构造器 public ProductCategoryExecution(ProductCategoryEnum stateEnum, List<ProductCategory> productCategoryList){ this.state = stateEnum.getState(); this.stateInfo = stateEnum.getStateInfo(); this.productCategoryList = productCategoryList; } 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 List<ProductCategory> getProductCategoryList() { return productCategoryList; } public void setProductCategoryList(List<ProductCategory> productCategoryList) { this.productCategoryList = productCategoryList; } }