通过枚举在Spring MVC中选择 [英] Select in Spring MVC by enum
本文介绍了通过枚举在Spring MVC中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< select name =country>
< c:forEach items =$ {countries}var =value>
< option value =$ {value}> $ {value}< / option>
< / c:forEach>
< / select>
我在类和表'User'字段字符串/ varchar'country'
解决方案
如果我理解正确,你将$ YourEnum.values()
添加到模型中,称为enumValues(根据下面的评论,这不是必需的)。
< form:select path =foo>
< form:option value = - label = - 请选择/>
< form:options items =$ {enumValues}/>
< / form:select>
参考:
What is way to select enum from database? I have:
<select name="country">
<c:forEach items="${countries}" var="value">
<option value="${value}">${value}</option>
</c:forEach>
</select>
I have in class and table 'User' field string/varchar 'country'
解决方案
Use the option and options tags from the spring forms tld.
If I understand it correctly, you will have to add YourEnum.values()
to the model, say as "enumValues" (according to comments below, this is not necessary).
<form:select path="foo">
<form:option value="-" label="--Please Select"/>
<form:options items="${enumValues}" />
</form:select>
Reference:
这篇关于通过枚举在Spring MVC中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文