使用枚举创建枚举常量池

date: 2018/11/12 10:08:31


常量类:常量枚举

/**
 * @description: 枚举常量由相当的优势相对于类常量(项目中推荐优先使用枚举常量)
 * @Author: yim
 * @Date: 2018/11/2 14:06
 **/
public enum OvlsConstant {

    LOGIN_SUCCESS(1,"登陆成功"),
    REGIST_SUCCESS(2,"注册成功"),
    INSERT_SUCCESS(3,"增加成功"),
    DELETE_SUCCESS(4,"删除成功"),
    UPDATE_SUCCESS(5,"修改成功"),
    QUERY_SUCCESS(6,"查询成功"),
    TOKEN_OK(7,"令牌合法"),
    TOKEN_ERROR(8,"令牌非法"),
    USER_EXISTS(9,"用户已存在"),
    USER_NO_EXISTS(10,"用户不存在"),
    PASSWORD_ERROR(11,"密码错误"),
    SYSTEM_ERROR(12,"系统异常");

    private int num;
    private String msg;

    private OvlsConstant(int num,String msg){
        this.num =num;
        this.msg = msg;
    }

    public int getNum() {
        return num;
    }

    public String getMsg() {
        return msg;
    }

    public static OvlsConstant getMsgByNum(int num){
        for (OvlsConstant oc: values() ) {
            if (oc.getNum() == num) {
                return oc;
            }
        }
        return null;
    }
}

你可能感兴趣的:(工作,开发集锦)