枚举类提示错误信息使用

package com.sf.QLAHP.Enum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
 
@ApiModel("01380217-柴亚春 -调度模块专用枚举类")
public enum DispatchEnum {
 
    BOY(0, "男"),
    GIRL(1, "女"),
    LADYBOY(2, "人妖"),
    SYSTEMERROR(4001, "系统发生数据错误或运行时异常"),
    DOUBLEORDERING(8016, "重复下单");
    
    @ApiModelProperty(value = "错误编码")
    private Integer code;
    
    @ApiModelProperty(value = "提示信息")
    private String message;
 
    DispatchEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
 
    public Integer getCode() {
        return code;
    }
 
    public String getMessage() {
        return message;
    }
    /**
     * 根据code获取当前的枚举对象
     * @param code
     * @return GenderColumn
     */
    public static DispatchEnum of(Integer code) {
        if (code == null) {
            return null;
        }
        for (DispatchEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
 


使用方法:

    //枚举类的使用
    public static void main(String[] args) {
         Integer code = DispatchEnum.BOY.getCode();
         String message = DispatchEnum.BOY.getMessage();
         System.out.println(code);
         System.out.println(message);
        
    }
        
        

猜你喜欢

转载自blog.csdn.net/chai1230/article/details/82759000