在我的模型中,变量Byte = 0;Byte = 1;
现在,low和high可以映射到字符串O1、O2、O3中的3个值;
例如,如果low =0它可以映射到O1,如果1它将映射到O2。这也是同样的高。
我应该如何设计我的控制器来通过JSP页面操纵这些值。
我有O1,O2,O3的枚举
喜欢
enum MyEnum {
O1(0),O2(1),O3(2) so on...
}我想要下拉的形式:选项,这将显示这三个枚举选项的低和高。
这里唯一的问题是我读过How do I set the selected value in a Spring MVC form:select from the controller?,但我无法理解我的Byte值将如何创建映射。我想填充这些值。
发布于 2013-04-08 14:11:14
首先,我认为您应该在模型中使用枚举,而不是字节。您始终可以从枚举中获取字节值。还将方法添加到模型类中,以返回枚举的字节值或字符串值。然后,在选中的输入框中使用此字符串值。
你(我的假设):
public enum MyEnum {
O1 (0),
O2 (1),
O3 (2);
private final Byte byteVal;
private MyEnum(Byte val) {
byteVal = val;
}
public Byte getByteVal(){
return byteVal;
}
}你的模型(我的假设):
public class MyModel{
MyEnum high; //instead of Byte high
MyEnum low;//instead of Bye low
....
//This method would return byte to be compatible with your backend as it is right now
public Byte getHigh(){
return this.high.getByteVal();
}
//This method would allow you to use the string representation for your front end
public Byte getHighString(){
return this.high.name();
}
}现在,在您的选择框中使用model.highString而不是jsp中的model.high。
希望这能有所帮助。
https://stackoverflow.com/questions/15880880
复制相似问题