JAVA----有时用枚举代替常量

JAVA----有时用枚举代替常量,第1张

JAVA----有时用枚举代替常量 有时用枚举代替常量 如结果集状态码为例,有状态码,状态信息等
@Getter
public enum ResultEnum {
    SUCCESS(0, "success"),
    FAIL(-1,"fail"),

    ERROR_400(400, "400"),
    ERROR_401(401, "401"),
    ERROR_402(402, "402"),
    ERROR_403(403, "403"),
    ERROR_404(404, "404"),
    ERROR_500(500, "500"),

	private Integer code;
    private String message;
    private String customMessage;


    
    ResultEnum(Integer code, String message, String customMessage) {
        this.code =  code;
        this.message = message;
        this.customMessage = customMessage;
    }

    ResultEnum(Integer code, String message) {
        this.code =  code;
        this.message = message;
    }

    public String getMessage() {
        if (customMessage != null) {
            return  customMessage;
        }

        return  MessageUtils.get(message);
    }


    
    public String getMessage(Object[] args) {
        if (customMessage != null) {
            return  customMessage;
        }

        return  MessageUtils.get(message, args);
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5162592.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-18
下一篇2022-11-18

发表评论

登录后才能评论

评论列表(0条)

    保存