如何填充组合框,从枚举中获取值
我有一个带有一个组合框的 jsp 页面,并且我有一个枚举类。
我想在 jsp 中填充组合框,填充后我想将这些值保存在 D/B 中,如何在 Struts 2 中做到这一点
public enum Roles {
ONE ("One"),
TWO ("Two"),
THREE ("Three"),
FOUR ("Four"),
FIVE ("Five"),
ALL ("All");
private final String displayValue;
private Roles(String displayString){
this.displayValue = displayString;
}
public String getDisplayString() {
return displayValue;
}
public static Roles getRoleOf(String displayValue){
if(displayValue.equals("One"))
return ONE;
if(displayValue.equals("Two"))
return TWO;
if(displayValue.equals("Three"))
return THREE;
if(displayValue.equals("Four"))
return FOUR;
if(displayValue.equals("All"))
return ALL;
else return ALL;
}
}
I have a jsp page with one combo box and I have a class which is an enum.
I want to populate my combo box in jsp and when it's populated I want to save these value in D/B how can I do it in Struts 2
public enum Roles {
ONE ("One"),
TWO ("Two"),
THREE ("Three"),
FOUR ("Four"),
FIVE ("Five"),
ALL ("All");
private final String displayValue;
private Roles(String displayString){
this.displayValue = displayString;
}
public String getDisplayString() {
return displayValue;
}
public static Roles getRoleOf(String displayValue){
if(displayValue.equals("One"))
return ONE;
if(displayValue.equals("Two"))
return TWO;
if(displayValue.equals("Three"))
return THREE;
if(displayValue.equals("Four"))
return FOUR;
if(displayValue.equals("All"))
return ALL;
else return ALL;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Roles.values() 获取所有枚举值并从那里开始。
you can use
Roles.values()
to get all the enum values and go from there.