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

xiaodong16 发布于 2015/05/23 09:36
阅读 240
收藏 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, AdminUser adminUser)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



加载中
0
JeffreyLin
JeffreyLin
试试:path="adminUser.roles"
0
xiaodong16
xiaodong16
这是form头部 <form:form method="post" action="adminUser_${adminUser.id == null ? 'add' : 'edit'}.do" commandName="adminUser">

这样写的话jsp显示报错
返回顶部
顶部