内容简介: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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Programming Ruby
Dave Thomas、Chad Fowler、Andy Hunt / Pragmatic Bookshelf / 2004-10-8 / USD 44.95
Ruby is an increasingly popular, fully object-oriented dynamic programming language, hailed by many practitioners as the finest and most useful language available today. When Ruby first burst onto the......一起来看看 《Programming Ruby》 这本书的介绍吧!