枚举类名建议带上 Enum 后缀,枚举成员名称需要全大写,单词间用下划线隔开。
说明:枚举其实就是特殊的类,域成员均为常量,且构造方法被默认强制是私有。 正例:枚举名字为 ProcessStatusEnum 的成员名称:SUCCESS / UNKNOWN_REASON。
public enum ResultEnum {
//成功
SUCCESS(200, "success"),
//学校300-399
SCHOOLCODEEXP(301, "学校代码不能为空!"),
SCHOOLNAME(302,"学校名称不能为空"),
SCHOOLAREA(303,"学校招生地区不能不空"),
NULL_SUBJECTTYPE(304,"科目类别不可为空"),
NULL_SCHOOLYEAR(305,"招生年限不可为空"),
SUBCOLNAME(306,"学科属性不能为空"),
ZSSFCODE(307,"招生省份编码不能为空"),
NULL_BATCH(308,"招生批次不能为空"),
//选科400-499
SELECTCOURSE(401,"所选科目不能为空"),
// 专业600-699
NULL_PARAM_MAJOR_LEVEL(601, "参数【专业层次】不可为空") ,
NULL_PARAM_MAJOR_CODE(602,"参数【专业代码】不可为空"),
NULL_DISCIPLINENAME(603,"参数【专业名称】不可为空"),
//录取批次线700-799
NULL_PARAM_PROVINCE(701, "参数【省份】不可为空"),
NULL_PARAM_EXAMINEE_CATEGORY(702, "参数【考生类别】不可为空"),
//职业信息800-899
NULL_PARAM_JOB_INFO_CODE(801,"参数【职业代码】不可为空"),
//公共异常
RUNEXECEPTION(500, "运行时异常"),
PAGEEXECPTION(901, "分页参数当前页面不能为空"),
PAGESIZEEXECPTION(902, "分页参数行数不能为空"),
PARAMXECEPTION(903, "参数非法"),
BIZEXECEPTION(904, "业务异常"),
UNDEFINE(-1, "未定义异常信息");
private int code;
private String msg;
ResultEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
public static String msg(int code) {
for (ResultEnum m : ResultEnum.values()) {
if (m.getCode() == code) {
return m.getMsg();
}
}
return UNDEFINE.getMsg();
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}