Enum类(name,index)
public enum BusinessTypeEnum {
gnmy(0,"国内贸易"),
dwmy(1,"对外贸易"),
wstz(2,"外商投资"),
jjhz(3,"经济合作"),
zhyw(4,"综合业务"),
qt(5,"其他");
private BusinessTypeEnum(int index,String name) {
this.index = index;
this.name = name;
}
private int index;
private String name;
public int getIndex() {
return index;
}
public String getName() {
return name;
}
}
重点:由于jsp页面中使用了 BusinessTypeEnum 枚举类,因此必须在该页面顶部引入 BusinessTypeEnum 类,否则下拉框中无法遍历枚举类!!!!!
<%@ page import="org.ciecc.xypt.datarecord.domain.BusinessTypeEnum " %>
JSP页面
<form:select path="businessType" cssClass="u-sel f-w200" >
<option value="" selected="true">全部</option>
<form:options items="${BusinessTypeEnum.values()}" itemLabel="name" itemValue="index"/>
</form:select>
说明:select 内 path中表示实体类对应的属性
option 内 items中传入枚举类的所有数据
itemLabel-----对应 Enum中 name
itemValue----对应 Enum中 index (枚举类中可不定义index,使用自带的,此处itemValue则可省略)
--------------------------------------------------------------------------------------------------------------------------------------------
枚举类中不设置index的写法
--------------------------------------------------------------------------------------------------------------------------------------------
public enum TestTypeEnum {
testone("测试1"),
testtwo("测试2"),
testthree("测试3")
;
private TestTypeEnum (String name) {
this.name = name;
}
private String name;
public String getName() {
return name;
}
重点:同理该页面必引入
<%@ page import="org.ciecc.xypt.datarecord.domain.TestTypeEnum" %>
<form:select path="test" cssClass="u-sel f-w200" >
<option value="" select="true">--请选择--</option>
<form:options items="${TestTypeEnum.values()}" itemLabel="name"/>
</form:select>