0
我有一個非常簡單的場景來處理。創建一個枚舉來表示選擇控件的一組選項。選擇控件需要將提示映射爲' - '作爲提示值。相應的枚舉沒有這個破折號。當提交頁面時,選擇控件仍然位於提示符處,引發異常。你如何處理這種情況?春季3:選擇值來枚舉值映射
頁:
<select id="filterUserAccessLevel" name="filterUserAccessLevel">
<option value="-">Select Value</option>
<option value="DEPOSITOR">Depositor</option>
<option value="READER">Reader</option>
<option value="AUTHOR">Author</option>
<option value="EDITOR">Editor</option>
<option value="ADMINISTRATOR">Administrator</option>
</select>
<input type="submit" name="resetFilter" value="<spring:message code="common.filterResetButtonLabel" />" />
UserAccessLevel枚舉:
public enum UserAccessLevel {
DEPOSITOR("DEPOSITOR"),
READER("READER"),
AUTHOR("AUTHOR"),
EDITOR("EDITOR"),
ADMINISTRATOR("ADMINISTRATOR");
private String code;
private UserAccessLevel(String code) {
this.code=code;
}
public String getCode() {
return this.code;
}
}
控制器:
@RequestMapping(value="/userIndex/", method=RequestMethod.POST, params="resetFilter")
public void resetFilter(@ModelAttribute("userIndexBean") UserIndexBean bean, Model model) {
System.out.println("resetFilter()");
bean.resetFilterSection();
loadBean(1, bean, model);
}
例外:
Field error in object 'userIndexBean' on field 'filterUserAccessLevel': rejected value [-];