开发者社区> 问答> 正文

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, 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
<p>
	<br>
</p>
<p>
	<br>
</p>

展开
收起
爱吃鱼的程序员 2020-06-14 15:52:28 417 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    试试:path="<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">adminUser.roles"这是form头部<form:formmethod="post"action="adminUser_${adminUser.id==null?'add':'edit'}.do"commandName="adminUser">

    这样写的话jsp显示报错

    2020-06-14 15:52:44
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

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