创建订单的时候,返回值为ResultVo为什么前端自动渲染页面,然而,返回值为一个map?就失败

来源:6-10 买家订单-api_A

zzylove

2019-06-05

@PostMapping("/create")
    public ResultVo<Map<String, String>> craete(@Valid OrderForm orderForm, BindingResult bindingResult)
    {
        if (bindingResult.hasErrors())
        {
            log.error("【创建订单】参数不正确, orderForm = {}",orderForm);
            throw new SellException(ResultEnum.PARAM_ERROR.getCode(), bindingResult.getFieldError().getDefaultMessage());
        }
        OrderDto orderDto = OrderForm2OrderDtoConverter.convert(orderForm);
        if (CollectionUtils.isEmpty(orderDto.getOrderDetailList()))
        {
            log.error("【创建订单】 购物车不能为空, orderdto = {}", orderDto);
            throw new SellException(ResultEnum.PRODUCT_STOCK_ERROR);
        }
        OrderDto createResult = orderService.create(orderDto);
        Map<String, String> map = new HashMap<>();
        map.put("orderid", createResult.getOrderId());

        return ResultVoUtil.success(map);
    }

如图,是师兄给出的代码,如果调整返回值

@PostMapping("/create")
    public Map<String, String> craete(@Valid OrderForm orderForm, BindingResult bindingResult)
    {
        if (bindingResult.hasErrors())
        {
            log.error("【创建订单】参数不正确, orderForm = {}",orderForm);
            throw new SellException(ResultEnum.PARAM_ERROR.getCode(), bindingResult.getFieldError().getDefaultMessage());
        }
        OrderDto orderDto = OrderForm2OrderDtoConverter.convert(orderForm);
        if (CollectionUtils.isEmpty(orderDto.getOrderDetailList()))
        {
            log.error("【创建订单】 购物车不能为空, orderdto = {}", orderDto);
            throw new SellException(ResultEnum.PRODUCT_STOCK_ERROR);
        }
        OrderDto createResult = orderService.create(orderDto);
        Map<String, String> map = new HashMap<>();
        map.put("orderid", createResult.getOrderId());

        return map;
    }

前端页面并不能渲染出我们想要的结果,请问这是个什么原理呢?

写回答

1回答

廖师兄

2019-06-06

返回map也是可以的。“然而,返回值为一个map?就失败”现象是什么,截图

0
0

Spring Boot双版本(1.5/2.1) 打造企业级微信点餐系统

从0到1开发中小型企业级Java应用,并学会迭代重构技巧

6410 学习 · 5247 问题

查看课程