axios get 传参数 数组

get 传参数 数组

this.$axios.get('/getUserByName',{
    params:{
        names:['qwe','asd'] + '',
    }
}).then(res=>{
    console.log(res)
})
//所形成的url为: /getUserByName?names=qwe,asd   等价于 /getUserByName?names=qwe&names=asd

springBoot 后端用数组接收

@GetMapping("/getUserByName")
@ApiOperation("根据名字查询人")
public List getUserByName(@RequestParam() String[] names){
    List<JSONObject> list = new ArrayList<>();
    for(int i = 0;i<names.length;i++){
        JSONObject json = new JSONObject();
        json.put("name",names[i]);
        json.put("sex","M");
        list.add(json);
    }
    return list;
}

猜你喜欢

转载自blog.csdn.net/Cribug8080/article/details/88343758