代碼:jsp
(1)單一枚舉this
public enum StatusEnum { CLAIM_YES("1"), //認領狀態 CLAIM_NO("0"); //未認領狀態 private final String value; public String getValue() { return value; } StatusEnum(String value) { this.value = value; } }
(2)鍵值spa
public enum ModuleTypeEnum { M1(1,"組1"),M2(2, "組2"); private int code; private String name; private ModuleTypeEnum(int code, String name){ this.code = code; this.name = name; } public int getCode() { return code; } public String getName() { return name; } /** * 根據code值獲取name值 * @param code * @return */ public static String getNameByCode(int code){ /*遍歷枚舉*/ for (ModuleTypeEnum moduleTypeEnum: ModuleTypeEnum.values()) { if (code == moduleTypeEnum.getCode()) { return moduleTypeEnum.getName(); } } return ""; }
jsp頁面調用枚舉code
(1)後臺代碼----向JSP頁面傳值(對象)對象
model.addAttribute("moduleTypeList", ModuleTypeEnum.values());
(2)get