java中restful风格

img


这样的参数&shoppingCartIds=33,34
后台怎么接啊
。。afhghkbnm。,

img

您好,如果需要接受数组对象的话,建议不要使用@PathVariable注解,使用@RequestParam,参考如下:
var itemList = ['31', '32', '33', '34', '35'];

$.ajax({
type: 'post', // get、post都行
dataType: 'json',
data: {
"payItem": itemList, // 支付项目编号
"payWay": 0, // 支付方式
"patientIdentity": "421023111101010011" // 身份证号
},
url: '/pay',
success: function (data) {
alert(data.msg);
}
})
@RequestMapping("/pay")
@ResponseBody
public Map<String, String> payApp(@RequestParam(value = "payItem[]") String[] payItem, Integer payWay, String patientIdentity) {
Map<String, String> parameter = new HashMap<>();
for (String item : payItem) {
System.out.println(item);
}
parameter.put("msg", "ok");
return parameter;
}
参考博客地址:https://blog.csdn.net/qq_45634592/article/details/124408170
希望可以帮到您

用 String 类型接参
接到后,用代码再转为数组

数组接,你的前段传参方式不对参数值直接跟在反斜杠后面

@PostMapping("getRecord1")
    public String test(@RequestParam Integer addressId,@RequestParam Integer[] shoppingCartIds){
        return null;
    }