springmvc中select可以绑定enum中所有数据的方法

public enum States
{
    AK("AK"), AL("AL"), AR("AR"), AZ("AZ"), CA("CA"), 
CO("CO"), CT("CT"), DC("DC"), DE("DE"), FL("FL"), 
GA("GA"), HI("HI"), IA("IA"), ID("ID"), IL("IL"), IN("IN"),
KS("KS"), KY("KY"), LA("LA"), MA("MA"), MD("MD"), ME("ME"), 
MI("MI"), MN("MN"), MO("MO"), MS("MS"), MT("MT"), NC("NC"), 
ND("ND"), NE("NE"), NH("NH"), NJ("NJ"), NM("NM"), NV("NV"), 
NY("NY"), OH("OH"), OK("OK"), OR("OR"), PA("PA"), RI("RI"), SC("SC"), 
SD("SD"), TN("TN"), TX("TX"), UT("UT"), VA("VA"), VT("VT"), WA("WA"), 
WI("WI"), WV("WV"), WY("WY");

    private String id;

    private States(String id)
    {
        this.id = id;
    }

    public String getId()
    {
        return id;
    }

now here is the code in my controller

Code:
    @ModelAttribute("states")
    public List<States> populateRoster()
    {
        return Arrays.asList(States.values());
    }

and finally the jsp

Code:
<td width="42%" align="left">
	<form:select path="resStateCode" > 
		<form:option value="0" label=" " />
		<form:options  items="${states}" itemValue="id" itemLabel="id" />
	</form:select>
</td>



package com.mofanghr.account.enums;

import java.util.*;

/**
 * Created by xiaoyuwang on 17/6/8.
 */
public enum  TsWorkBenchEnum {

    TODAY_CONTACT("今日计划联系的客户", 1), FIFTEEN_NOT_CONTACT("15天未联系的客户", 2),
    TODAY_FOUR_PROCESS("今日新达到第4进程的客户", 3), TODAY_FIVE_PROCESS("今日新达到第5进程的客户", 4),
    REGISTER_USER_ASSIGN("新注册的客户待分配", 5),TODAY_NEW_USER_ASSIGN("今日系统新增的客户待分配", 6),
    TS_CONFIRM_VISIT("到访待确认",7),TS_BE_VERIFY("待审核人数",8);
    private String name ;
    private int index ;

    TsWorkBenchEnum( String name , int index ){
        this.name = name ;
        this.index = index ;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getIndex() {
        return index;
    }
    public void setIndex(int index) {
        this.index = index;
    }

    public static List<TsWorkBenchEnum> getListForMy(){

        return Arrays.asList(TsWorkBenchEnum.values()).subList(0,4);
    }
    public static List<TsWorkBenchEnum> getListForDistribute(){

        return Arrays.asList(TsWorkBenchEnum.values()).subList(4,6);
    }

}

  

<form:select id="tsWorkBenchType" path="tsWorkBenchType" class="mf-select">
    <form:option value="0">不限</form:option>
    <form:options items="${workbenchTypeList}" itemLabel="name" itemValue="index" />
</form:select>

  

posted @ 2017-06-12 14:04 PointNet 阅读(...) 评论(...) 编辑 收藏