标签:mic ati print 不同 comm strong base 参数 get
1.前端不做处理,
var roleIds = new Array(); $("input[name=‘uRole‘]:checked").each(function(index,element){ let roleId = $(element).attr("data-roId"); roleIds[index] = roleId; }); $.ajax({ type: "post", url: baseUrl + "/userManage/updateUserRole",//对应controller的URL async: true, dataType: ‘json‘, data: { "array": roleIds }, success:
后端接收:
String[] array = req.getParameterValues("array[]"); if (!StringUtils.isEmpty(array)) for (String string : array) { System.out.println("直接获取传递的数组参数:"+string); } else System.out.println("直接获取传递的数组参数为空");
2.以json字符串形式传递到Java后端
$.ajax({ type: "post", url: baseUrl + "/userManage/updateUserRole",//对应controller的URL async: true, dataType: ‘json‘, contentType : "application/json", data: JSON.stringify(roleIds),//json对象转化为json字符串 success: function (ret) { console.log(ret); }
后端接收:
@RequestMapping(value = "/updateUserRole") @ResponseBody public String updateUserRole(HttpServletRequest req,@RequestBody String[] roleIdsss) { if (!StringUtils.isEmpty(roleIdsss)) for (int i = 0; i < roleIdsss.length; i++) { String idsss = roleIdsss[i]; System.out.println("requestBody获取传递的json数组参数:" + idsss); } else System.out.println("requestBody获取传递的json数组参数为空");
两种post请求的content-type不同
参考链接:
https://blog.csdn.net/u012838207/article/details/80519375
标签:mic ati print 不同 comm strong base 参数 get
原文地址:https://www.cnblogs.com/erlongxizhu-03/p/12337133.html