• gson格式化参数 对象转Map


    前台传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());
        }
    }
  • 相关阅读:
    4.比赛F
    4.M
    4.H
    4.J
    4.G
    4.D
    4.C
    UVA 215 Spreadsheet Calculator (模拟)
    POJ 3469 Dual Core CPU(最小割模型的建立)
    POJ 3281 Dining(网络流最大匹配)
  • 原文地址:https://www.cnblogs.com/Eeexiang/p/10239564.html
Copyright © 2020-2023  润新知