前台传json到后台接收:
String params = request.getParameters("paramtes");
Map<String, Map<String,Object>> searchMap = new Gson().fromJson(searchParams, new TypeToken<HashMap<String, Map<String, String>>>() {
}.getType());
例子:
/** * 批量封禁用户 * @param listJson * @param logId * @return */ @RequestMapping(value = "/reportManager/batchFreezeUser", method = RequestMethod.POST) @ResponseBody public OperateResponse batchFreezeUser(@RequestParam(value = "listJson") String listJson, @LogId Long logId) { List<Map<String, Object>> json = new Gson().fromJson(listJson, new TypeToken<List<Map<String, Object>>>() { }.getType()); //用gson转换成json对象 json.stream().forEach(item->{ long userId = Long.parseLong(item.get("userId").toString()); String freezeReason = item.get("freezeReason").toString(); reportService.closureUser(userId, freezeReason, 0, logId); }); return OperateResponse.obtainSuccessResponse(json.size()); } }