前台传list,后台怎么接取(java实现)

前台请求:

    var groupList=new Array();
    var group={
		groupId:1,
		groupName:"测试"
	}
	groupList.push(group);
	$.ajax({
		data:{
			packageId:7,
			name:"修改名称测试包",
			groupListStr:JSON.stringify(groupList)
		},
		url:"baidu.com",
		async:false,
		type:"get"
	});

后台代码:

@RequestMapping(value = "/users/transfer", method = RequestMethod.GET, produces = "application/json")
    public JsonResult groupListTransfer(
            @ApiParam(name = "fPId", value = "包Id", required = true) @RequestParam Integer fPId,
            @ApiParam(name = "groupListStr", value = "组listStr", required = true) @RequestParam String groupListStr) {
        JSONArray arrayList= JSONArray.parseArray(groupListStr);
        //转换为目标对象list
        List groupList = JSONObject.parseArray(arrayList.toJSONString(), T.class);
        return new JsonResult().ok(doSth(fPId,groupList));
    }

后台通过JSONArray.parseArray(String)把 string转成JSONArray对象。

然后通过JSONObject.parseArray()转化为你想要的对象list,T为目标对象。

你可能感兴趣的:(技术)