【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>
@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>
相关文章推荐
- SpringMVC 在业务控制方法中收集数组及List<JavaBean>参数
- springmvc中,在业务控制方法中,收集数组参数,收集List集合包含javabean
- springmvc在业务控制方法中收集List<JavaBean>参数,实现批量处理
- 在业务控制方法中收集List<JavaBean>参数 (例如 同时添加多个用户) (12)
- springmvc中一个Action中,写多个类似的业务控制方法+在业务控制方法中写入普通变量收集参数+限定某个业务控制方法。只允许GET或POST请求方式访问
- 业务控制方法中收集数组参数 (例如 批量删除用户) (11)
- SpringMVC 在业务控制方法中写入模型变量收集参数,且使用@InitBind来解决字符串转日期类型
- 【SpringMVC】在业务控制方法中写入User,Admin多个模型收集参数(十四)
- Springmvc中,在业务控制方法中写入包装类收集参数
- <转>根据泛型生成数组 与数组 List相互转换的方法
- List<T>的ForEach方法(可以使用“语句lambda”作为其参数),如下例子:
- springmvc中,结果的转发可以共享request域对象,会将参数从第一个业务控制方法传入第二个业务控制方法,重定向则不行
- .NET中string[]数组和List<string>泛型的相互转换以及Array类的Sort()方法(转)
- List<T>集合导出csv方法参考,通过增加自定义的属性控制输出的字段。
- List<T>泛型数组API自带的Sort() 排序方法根据自定义排序实现
- 在控制类的方法参数中利用javabean(实体类)来收集参数 (10)