Springmvc接收数组参数,必须添加@RequestParam注解

注解格式@RequestParam(value="前端参数名[]")

示例:

controller端的代码

@RequestMapping("/array")
    public void getArray(@RequestParam(value="datas[]") String[] names) {
        for(int i=0;i<names.length;i++) {
            System.out.println(names[i]);
        }
    }

前台请求代码

var bearnames = ['熊大',"熊二"];
    $.ajax({
        type:'post',
        url:'/FileUpload/flowerController/array',
        data:{
            //datas为前端参数名
            datas:bearnames
        },
        cache : false,
        success:function(){
            alert('参数传递成功');
        },error:function(){
            alert('参数传递失败');
        }
    })

 

相关文章:

  • 2021-11-10
  • 2021-08-16
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2021-06-12
  • 2022-02-09
猜你喜欢
  • 2021-12-25
  • 2022-01-01
  • 2021-08-07
  • 2021-09-20
  • 2021-10-21
  • 2021-12-15
相关资源
相似解决方案