您的位置:首页 > 编程语言 > Java开发

【SpringMVC】在业务控制方法中收集数组与List<JavaBean>参数(十五)

2017-11-21 14:20 489 查看
1)批量删除用户
@Controller
@RequestMapping(value="/user")
public class UserAction {
@RequestMapping(value="/delete")
public String deleteMethod(int[] ids,Model model) throws Exception{
System.out.println("UserAction::deleteMethod()");
System.out.println("需要删除的id为:");
for(int id : ids){
System.out.print(id+" ");
}
model.addAttribute("message","批量删除成功");
return "/success.jsp";
}
}

2)批量注册用户
UserAction.java

@Controller
@RequestMapping(value="/user")
public class UserAction {
@RequestMapping(value="/addAll")
public String addAll(Bean bean,Model model) throws Exception{
for(User user : bean.getUserList()){
System.out.println(user.getName()+":"+user.getGender());
}
model.addAttribute("message","批量增加用户成功");
return "/success.jsp";
}
}

    Bean.java

public class Bean {
private List<User> userList = new ArrayList<User>();
public Bean(){}
public List<User> getUserList() {
return userList;
}
public void setUserList(List<User> userList) {
this.userList = userList;
}
}

    registerAll.java

<form action="${pageContext.request.contextPath}/user/addAll.action" method="POST">

姓名:<input type="text" name="userList[0].name" value="哈哈"/>
性别:<input type="text" name="userList[0].gender" value="男"/>
<hr/>
姓名:<input type="text" name="userList[1].name" value="呵呵"/>
性别:<input type="text" name="userList[1].gender" value="男"/>
<hr/>

姓名:<input type="text" name="userList[2].name" value="嘻嘻"/>
性别:<input type="text" name="userList[2].gender" value="女"/>
<hr/>
<input type="submit" value="批量注册"/>
</form>

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐