枚举根据ordinal值获取对应文本

自定义valueOf(int ordinal)方法,获取文本值

public enum Stage implements BaseEnums {
	PRE("学前"),
	PRIMARY("小学"),
	MIDDLE("初中"),
	HIGH("高中"),
	TECHNICAL("中专、中职"),
	//COLLEGE("大学"),
	OTHER("其它");
	
	private String text;

	Stage(String text) {
		this.text = text;
	}
	public int getValue() {
		return this.ordinal();
	}
	public String getText() {
		return text;
	}
	static String values[] = {"学前","小学","初中","高中","中专、中职","其它"};
	public static String valueOf(int ordinal){
		if (ordinal < 0 || ordinal >= values().length) {
            throw new IndexOutOfBoundsException("Invalid ordinal");
        }
		return values[ordinal];
	}
}


你可能感兴趣的:(枚举根据ordinal值获取对应文本)