前段时间做个后台管理系统的用户注册功能,在新用户注册时候,要插入用户所在部门的id和职务id,而且用户roles类型是list型,所以在jsp页面传值时候就出现了List类型转化错误,搞了好半天草解决,解决办法如下:
将原来的传值方式:
<div>
<input type="radio" name="staff.roles" value="1" id="staffroles" />
<label for="staffType1">英语编辑</label>
<input type="radio" name="staff.roles" value="2" id="staffroles"/>
<label for="staffType0">语文编辑 </label>
</div>
改为:
<div>
<s:radio name="staffroles" list="#{'1':'英语编辑','2':'语文编辑'}" ></s:radio>
</div>
这样在选择radio时候就能传整型值了,但还要在程序中就行转换,具体如下:
//提取jsp页面信息并装换为整型
String staffroles=request.getParameter("staffroles");
int int_staffroles=Integer.parseInt(staffroles);
然后通过将所获取的int_staffroles直接插入关联表就ok了。