• 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());
        }
    }
  • 相关阅读:
    单向循环列表(Java实现)
    单链表的实现(Java实现)
    二分查找法(Java实现)
    六大排序算法(Java实现)
    学习python第十天
    学习python第九天
    MapNode
    AtomicReference
    AtomicStampedReference
    尾递归(TailRecursion)
  • 原文地址:https://www.cnblogs.com/Eeexiang/p/10239564.html
Copyright © 2020-2023  润新知