枚舉列表 根據編號獲取對應的內容

package com.module.policy_manage.model.enums;

/**
 * 扶持事項type字段 類型  枚舉類
 * @author asus
 *
 */
public enum SupportMatterTypeEnum {
	HELP_FINANCE(1,"助融資"),
	PROMOTE_INNOVATION(2,"促創新"),
	STRONG_INDUSTRY(3,"強產業"),
	SUPPORT_GROW_UP(4,"扶成長"),
	LEAD_TALENT(5,"引人才")	
	;
	
	private Integer typeCode;
	private String typeName;
	private static final SupportMatterTypeEnum[] typeEnum = SupportMatterTypeEnum.values();
	private static final int length = typeEnum.length;
	
	SupportMatterTypeEnum(Integer typeCode,String typeName){
		this.typeCode = typeCode;
		this.typeName = typeName;
	}

	public Integer getTypeCode() {
		return typeCode;
	}

	public String getTypeName() {
		return typeName;
	}
	
	/**
	 * 根據編號 獲取類型名稱
	 * @param code
	 * @return
	 */
	public static String getTypeName(int code){
		if(code > 0 && code <= length){
			return typeEnum[code - 1].getTypeName();
		}
		return null;
	}
	
	
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章