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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章