Ajax提交与Form表单提交数组

Ajax 提交数组

@PostMapping("/save")
public void saveUser( @RequestParam("userRole[]") List<Integer> roleIds) {
$.post('/save',{ userRole:[10002,30043] },function(data){
  //todo 
});

Form表单提交数组

普通第一种方式就够了,第二种属于要上传附件,还要提交数组。当然了不上传附件也可以用啦!!!

@PostMapping("/save")
public void saveUser(@RequestParam("file") MultipartFile file,@RequestParam("userRole") List<Integer> roleIds){
  <form action="user/save"
          enctype="multipart/form-data"
        method="post">
    <!-- 额外的,如果没有不需要 -->
    <input type="file" name="file" />
		<input type="text" name="userRole" value="100003"/>
    <input type="text" name="userRole" value="200004"/>
  </form>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章