【问题标题】:Spring not allowing RequestMethod.DELETESpring不允许RequestMethod.DELETE
【发布时间】:2015-10-28 14:49:51
【问题描述】:

我有这个端点调用我的服务方法,然后调用我的 repo 类来删除用户,但是当我通过邮递员调用这个端点时,我得到一个请求方法不支持”打印在控制台中,任何帮助都会很大赞赏

@RequestMapping(value = "/{useId}/delete-user", method = RequestMethod.DELETE)
    public ResponseEntity<String> deleteUser(@PathVariable("userId") String userId){
        ResponseEntity<String> response = null;
        try {
            validate(userId);
            userService.deleteUser(Long.parseLong(userId));
            response = new ResponseEntity<String>(HttpStatus.NO_CONTENT);
        }catch (InputMismatchException e){
            response = new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
        } catch (UserNotFoundException e) {
            response = new ResponseEntity<String>(HttpStatus.NOT_FOUND);
        } catch (AccessDeniedException e) {
            response = new ResponseEntity<String>(HttpStatus.FORBIDDEN);
        }
        return  response;
    }

收到的消息是Request method 'DELETE' not supported

【问题讨论】:

  • 您在 RequstMapping 值中有一个类型(useId 而不是 userid)...这可能是原因
  • jny 你能不能把它作为答案而不是 od 评论,所以我可以给你功劳

标签: spring-security spring-boot spring-restcontroller


【解决方案1】:

@RequestMapping 中有错字。 userid 拼写错误。这就是为什么 Spring 没有将 DELETE 映射到 deleteUser 方法

【讨论】:

    猜你喜欢
    • 2022-10-24
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 2022-01-07
    相关资源
    最近更新 更多