绑定一个数组

  1. <form action="param-bind-array.action" method="post">
  2. <input type="checkbox" name="enjoy" value="1">LOL
  3. <input type="checkbox" name="enjoy" value="2">DNF
  4. <input type="checkbox" name="enjoy" value="3">CF
  5. <input type="checkbox" name="enjoy" value="4">DOTA
  6. <input type="checkbox" name="enjoy" value="5">WOW
  7. <P>
  8. <input type="submit" value="走你">
  9. </P>
  10. </form>
@RequestMapping("/param-bind-array") 
@ResponseBody //使用数组接收 
public String paramBindArray(int [] enjoy){ return Arrays.toString(enjoy); }

复杂参数绑定

<form action="param-bind-vo.action" method="post"> 
  <hgroup> 
    学科名称:<input type="text" name="subjects[0].subjectname"><br/> 
    学科描述:<input type="text" name="subjects[0].subjectdesc"><br/> 
  </hgroup> 
  <hgroup> 
    学科名称:<input type="text" name="subjects[1].subjectname"><br/> 
    学科描述:<input type="text" name="subjects[1].subjectdesc"><br/> 
  </hgroup> 
  <hgroup> 
    学科名称:<input type="text" name="subjects[2].subjectname"><br/> 
    学科描述:<input type="text" name="subjects[2].subjectdesc"><br/> 
  </hgroup> 
  <p> 
    <input type="submit" value="提交"> 
  </p> 
</form>

额外定义一个用于接收参数的类

public class SubjectVO { 
    //当然也可以有其他的属性 
    //必须有一个集合 
    private List<Subject> subjects; 
    public List<Subject> getSubjects() { return subjects; }
    public void setSubjects(List<Subject> subjects) { this.subjects = subjects; } 
}

后端控制器

@RequestMapping("/param-bind-vo") 
@ResponseBody //使用VO对象接收 
public SubjectVO paramBindVo(SubjectVO subjectVO){ return subjectVO; }