开发者社区> 问答> 正文

springmvc 4+hibnate 4.0 复选框无法保存的问题

实例类多对多映射,ID都是Long

private Set<Role> roles = new HashSet<Role>();
private Set<AdminUser> adminUsers = new HashSet<AdminUser>();

现在问题是复制框保存时出错
 

<form:checkboxes path="roles" items="${roleList}"
itemValue="id" itemLabel="name"/>


控制层

public String edit(HttpServletRequest request,<span></span> AdminUser adminUser<span></span>)throws Exception {
....
}
接收adminUser adminUser 就报错,好像是类型转换问题,不知如何解决?
接收string[] roles 就不报错。

Field error in object 'adminUser' on field 'roles': rejected value [1,2,3]; codes [typeMismatch.adminUser.roles,typeMismatch.roles,typeMismatch.java.util.Set,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [adminUser.roles,roles]; arguments []; default message [roles]]; default message [Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.Set' for property 'roles'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.szqws.trj.entity.Role] for property 'roles[0]': no matching editors or conversion strategy found]
2015-05-23 09:41:32,578 - DEBUG - Resolving exception from handler [public java.lang.String com.szqws.trj.admin.controller.AdminUserController.edit(javax.servlet.http.HttpServletRequest,com.szqws.trj.entity.AdminUser) throws java.lang.Exception]: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors

展开
收起
a123456678 2016-03-18 10:29:03 2015 0
1 条回答
写回答
取消 提交回答
  • 这是form头部

    <form:form method="post" action="adminUser_${adminUser.id == null ? 'add' : 'edit'}.do" commandName="adminUser">
    2019-07-17 19:06:04
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载