execution返回值不对?

来源:5-4 秒杀交互

东方明月

2017-06-12 11:42

可以秒杀成功,但是重复秒杀的时候。execution的Response是{"success":false,"data":{"seckillId":1000,"state":-2,"stateInfo":"系统异常","successKilled":null},"error":null}。

写回答 关注

1回答

  • qq_文醒_0
    2017-07-13 20:03:51

    修改一下,SeckillController 类中的  加粗的位置即可

    @ResponseBody
    @RequestMapping(value = "/{seckillId}/{md5}/execution", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public SeckillResult<SeckillExecution> execute(@PathVariable("seckillId") Long seckillId,
                                                  @PathVariable("md5") String md5,
                                                  @CookieValue(value = "killPhone", required = false) Long phone) {
       if (phone == null){
           return new SeckillResult<SeckillExecution>(false,"未注册登录的用户");
       }
       try {
           SeckillExecution seckillExecution = seckillService.executeSeckill(seckillId, phone, md5);
           return new SeckillResult<SeckillExecution>(true,seckillExecution);
       }catch (RepeatKillException e){
           SeckillExecution execution = new SeckillExecution(seckillId, SeckillStateEnum.REPEAT_KILL);
           return new SeckillResult<SeckillExecution>(true,execution);
       }catch (SeckillCloseException e){
           SeckillExecution execution = new SeckillExecution(seckillId, SeckillStateEnum.END);
           return new SeckillResult<SeckillExecution>(true,execution);
       }catch (Exception e){
           logger.error(e.getMessage(),e);
           SeckillExecution execution = new SeckillExecution(seckillId, SeckillStateEnum.INNER_ERROR);
           return new SeckillResult<SeckillExecution>(true,execution);
       }
    }

Java高并发秒杀API之web层

Java实现高并发秒杀API的第三门课,介绍Web层的设计和实现

66079 学习 · 395 问题

查看课程

相似问题