JAVA 定义常量类和枚举

1:定义常量类

/**
 * @Author:Starry
 * @Description:常量类定义
 * @Date:Created in 10:08 2018/4/13
 * Modified By:
 */
public interface ServiceConst {

    /** 逻辑删除标记 **/
    interface DELETE_FLAG{
        /** 默认值0 未删除 **/
        Integer FALSE = 0;
        /** 已删除 **/
        Integer TRUE = 1;
    }

    /** 表名 **/
    interface TABLE_NAME{
        /** 订单表 **/
        String ORDER = "table_order";
        /** 用户表 **/
        String USER = "center_user";
    }
}

2:定义枚举


/**
 * 操作日志枚举
 * @Author:Starry
 * @Description:
 * @Date:Created in 10:22 2018/4/13
 * Modified By:
 */
public enum EventTypeEnum {
    INSET(1,"新增操作"),
    UPDATE(2,"修改操作"),
    DELETE(3,"删除操作");

    Integer code;//状态编号
    String name;//状态名称

    //构造方法
    EventTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getName(Integer code){
        for(EventTypeEnum evenEnum : EventTypeEnum.values()){
            if(evenEnum.getCode().equals(code)){
                return evenEnum.getName();
            }
        }
        return null;
    }

    //成员方法
    public Integer getCode() {
        return code;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

你可能感兴趣的:(java基础)