当您
Authority是复杂的bean
时,HTML表单仅适用于字符串值。您需要配置,
PropertyEditor以在
Authority和之间执行转换
String:
@InitBinder public void initBinder(WebDataBinder b) { b.registerCustomEditor(Authority.class, new AuthorityEditor());}private class AuthorityEditor extends PropertyEditorSupport { @Override public void setAsText(String text) throws IllegalArgumentException { setValue(authorityService.findById(Long.valueOf(text))); } @Override public String getAsText() { return ((Authority) getValue()).getId(); }}


