1 <form method="post" action="http://localhost/ExamOnline/page/test/list2"> 2 3 id<input type="text" name="id"><br/> 4 id<input type="text" name="id"><br/> 5 id<input type="text" name="id"><br/> 6 <input type="submit"> 7 </form>
1 @RequestMapping("/test/list1") 2 @ResponseBody 3 public String testlist(@RequestParam("id") List<Integer> ids) { 4 5 for (Integer integer : ids) { 6 System.out.println(integer); 7 } 8 return "ok"; 9 }
1 @RequestMapping("/test/list2") 2 @ResponseBody 3 public String testlist(String id) { 4 5 System.out.println(id); 6 return "ok"; 7 }
1 <form method="post" action="http://localhost/ExamOnline/page/test/list3"> 2 3 id<input type="text" name="ques[0].id"><br/> 4 name<input type="text" name="stu[0].title"><br/> 5 id<input type="text" name="ques[1].id"><br/> 6 name<input type="text" name="stu[1].title"><br/> 7 id<input type="text" name="ques[2].id"><br/> 8 name<input type="text" name="stu[2].title"><br/> 9 <input type="submit"> 10 </form>
1 @RequestMapping("/test/list3") 2 @ResponseBody 3 public String testpojolist(RequestModel bean) { 4 5 for (Question q : bean.getQues()) { 6 System.out.println(q.getTitle()); 7 } 8 9 return "ok"; 10 }
1 //get、set函數必不可少,反射必用 2 public class RequestModel { 3 4 private List<Question> ques; 5 public List<Question> getQues() { 6 return ques; 7 } 8 public void setQues(List<Question> ques) { 9 this.ques = ques; 10 } 11 12 }