参数返回例子

1.返回Map集合到前台:

 	@GetMapping("/role_change/userList")
    @ResponseBody
    public Object userList(UserPrinciple userPrinciple) {
  		List<Map<String, Object>> results = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("adminState", "1");
        map.put("userList", reportService.cutOverUsers(userPrinciple.getUser().getRoleId()));//超管界面
        results.add(map);
        return results;
    }

2.List嵌套Map集合到前台:

2.1:service
      public List<HashMap<Object, Object>> updateGroupItems(List<OrganizationGroup> organizationGroup) {
        //存储返回
        List<HashMap<Object, Object>> list = new ArrayList<HashMap<Object, Object>>();
        organizationGroup.forEach(q -> {
            HashMap<Object, Object> maps = new HashMap<Object, Object>();
            //存map返回 id 和对应idkey
            maps.put("id", q.getIdKey());
            maps.put("organizationId", q.getIdKey());
            maps.put("idKey", q.getIdKey());
            list.add(maps);
            // 利用list中的元素创建HashSet集合,此时set中进行了去重操作
            HashSet set = new HashSet(list);
            // 清空list集合
            list.clear();
            // 将去重后的元素重新添加到list中
            list.addAll(set);
        });
        return list;
    }
        

2.2:controller层

   @RequestMapping("/groupItemChange")
    @CustomerVisitHistory
    public Object groupItemChange(@RequestBody List<OrganizationGroup> organizationGroup, HttpServletRequest req) {
        Map maps = new HashMap<String, String>();
        if (organizationGroup != null) {
            Map<String, String> map = JWTUtil.verificationToken(req.getHeader("token"));
            if (StringUtils.containsIgnoreCase(map.get("message"), "success")) {
                //接收参数机构数据 进行修改
                List<HashMap<Object, Object>> hashMaps = organizationUserService.updateGroupItem(organizationGroup);
                if (hashMaps != null) {
                    maps.put("return", hashMaps);
                    maps.put("Message", "Succeed");
                } else {
                    maps.put("return", hashMaps);
                }
            } else {
                maps.put("NoLogin", "请输入正确Token");
            }

        }
        return maps;
    }

2.3 响应示例
响应示例

3.Map互相调用:

	控制层:
    public String userUserAgencyDiscount() {
        var loginUser = getLoginUser();
        var req = readJson();
        var discountState = (Integer) req.get("discountState");
        var result = new HashMap<String, Object>();
        result.put("success", 0);
        Map map = cnUserService.editUserDiscountState(discountState);
        Integer succeed = (Integer) map.get("succeed");
        String error = (String) map.get("error");
        if (succeed > 0) {
            result.put("success", 1);
        } else {
            result.put("error", error);
        }
        writeJson(result);
        return null;
    }
	

	Service:
	  Map editUserDiscountState(Integer discountState);

	Serviceimpl@Override
    public Map editUserDiscountState(Integer discountState) {
        var loginUser = getLoginUser();
        var result = new HashMap<String, Object>();
        result.put("succeed", 0);
        if (discountState != null) {
            //存在编辑
            int i = userMapper.editUserDiscountState(discountState, loginUser.getId());
            if (i > 0) {
                result.put("succeed", 1);
                userMapper.insertDiscountStatusRecords(new CnUserDiscountStatusRecords(loginUser.getId(), LocalDateTime.now(), "编辑"));//操作日志
            } else {
                result.put("error", "数据错误,修改失败!");
            }

        } else {
            result.put("error", "数据错误,请联系管理员!");
        }
        return result;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值