Enum类
/**
*
*/
package com.example.enums;
/**
* @author Administrator
*
*/
public enum EnumType {
BLOG("blog", "博客"),
QUESTION("question", "提问"),
ESSAY("essay", "随笔");
private String code;
private String desc;
private EnumType(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static EnumType getCode(String code) {
for (EnumType type : EnumType.values()) {
if (type.getCode().equals(code)) {
return type;
}
}
return null;
}
/**
* @return the code
*/
public String getCode() {
return code;
}
/**
* @param code the code to set
*/
public void setCode(String code) {
this.code = code;
}
/**
* @return the desc
*/
public String getDesc() {
return desc;
}
/**
* @param desc the desc to set
*/
public void setDesc(String desc) {
this.desc = desc;
}
}
页面
<%@page import="com.example.enums.EnumType"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="types" value="<%= EnumType.values() %>"/>
<c:forEach var="type" items="${types}">
${type.getCode() }, ${type.getDesc() }
</c:forEach>
参考链接:http://blog.csdn.net/kinginblue/article/details/51458576