一、枚举类

package com.xxx.xf.common.enums;

import com.xxx.xf.workday.contant.HolidayContant;

/**
 * @Author: wangmq
 * @Version: 1.0
 * 操作枚举类
 */
public enum XfOperateEnum {

    // 定义多个由构造方法组成的对象,逗号隔开分号为结束
    XF_OPERATE_SL("SL","受理", 3,  HolidayContant.NATURAL_DAY),
    XF_OPERATE_BL("BL","办理", 3,  HolidayContant.WORKING_DAY),
    XF_OPERATE_BJ("BJ","办结", 60, HolidayContant.NATURAL_DAY);

    // 该枚举类构造方法所用的属性
    // 标识code
    private String code;
    // 该操作名称
    private String value;
    // 时限天数
    private int amount;
    // 时限类别,工作日和自然日
    private String amountType;

    // 通过code属性获取对应的枚举对象
    // XfOperateEnum.values() 返回值是所有枚举类对象
    public static XfOperateEnum getXfOperateEnumByCode(String code){
        for(XfOperateEnum xfOperateEnum : XfOperateEnum.values()){
            if(xfOperateEnum.code.equalsIgnoreCase(code)){
                return xfOperateEnum;
            }
        }
        return null;
    }

    // 该枚举类的全参构造方法
    XfOperateEnum(String code, String value, int amount, String amountType) {
        this.code = code;
        this.value = value;
        this.amount = amount;
        this.amountType = amountType;
    }

    // 私有属性的set和get方法
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getAmountType() {
        return amountType;
    }

    public void setAmountType(String amountType) {
        this.amountType = amountType;
    }

}

二、枚举类使用

// 获取该枚举类某个对象的某个属性值
XfOperateEnum.XF_OPERATE_SL.getCode()

dd

02-12 00:41