我的关系如下
USER USER-SKILL SKILL
id userid id
title skillid title
level
你如何看待我需要为用户添加一些技能(并将数据添加到额外的字段"级别"),为简单起见,我们假设我们创建了一个新用户并添加了现有技能。
所以我做了什么:
控制器
@RequestMapping(value = "insterpage", method = RequestMethod.GET)
public String insertPageGet(ModelMap model) {
model.addAttribute("listAttribute", new ArrayList<UserSkill>());
model.addAttribute("userAttribute", new User());
return "insertpage";
}
@RequestMapping(value = "insterpage", method = RequestMethod.POST)
public String insertPagePost(ModelMap model, @ModelAttribute("userAttribute") User user, @ModelAttribute("listAttribute") List<UserSkill> userskill) {
user.setUserSkills(list); // all the details of the assignment skills to user i skipped here, because it is not important here
userService.insert(user);
return "userlist";
}
JSP页面
<form:form modelAttribute="userAttribute">
<form:label path="title">Title</form:label>
<form:input path="title"/>
</form:form>
<form:form modelAttribute="listAttribute">
<!-- loop here, i want insert 10 times different skills -->
<form:label path="level">Level</form:label>
<form:input path="level"/>
<form:hidden path="skill" value="{skill.id}">
</form:form>
<input type="submit" value="Submit">
虽然这两种形式,使用jQuery(函数serialize())我可以发送属性到控制器。我想知道如何发送多个对象并将其放入上面的列表中。
我该如何处理?有什么想法吗?