axios SpringMvc String[] 字符串数组传递

前端

  axios.post("/getByUserIds",
                    qs.stringify(
                        {"userIds": userIds},  //userIds=["1","2","3"]
                        {indices: false}) //该参数控制影响后台接收,参数传递格式(userIds=1&userIds=2&userIds=3)
                ).then(
                    function (response) {
                        console.log(response);
                    })
                    .catch(function (error) {
                        console.log(error);
                    });

axios SpringMvc  String[] 字符串数组传递

后端

 @RequestMapping(value = "/validBatchUploadSettleCertificate", method = RequestMethod.POST)
public Result getByUserIds(@RequestParam("userIds") String[] userIds) {
    System.out.println(userIds);
}

qs.stringify indices格式

qs.stringify({userIds: [1, 2, 3]}, { indices: false })
 //形式: userIds=1&userIds=2&userIds=3
qs.stringify({userIds: [1, 2, 3]}, {arrayFormat: ‘indices‘})
 //形式: userIds[0]=1&userIds[1]=2&userIds[2]=3
qs.stringify({userIds: [1, 2, 3]}, {arrayFormat: ‘brackets‘})
 //形式:userIds[]=1&userIds[]=2&userIds[]=3
qs.stringify({userIds: [1, 2, 3]}, {arrayFormat: ‘repeat‘}) 
//形式: userIds=1&userIds=2&userIds=3
上一篇:JavaScript对象转换为字符串、字符串转换为对象


下一篇:微信分享