我有这个端点调用我的服务方法,后者又调用我的repo类来删除用户,但是当我通过postman调用这个端点时,我得到一个请求方法不支持“打印在控制台中,任何帮助都会很大赞赏
@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
答案 0 :(得分:1)
@RequestMapping
中有一个拼写错误。 userid
拼写错误。这就是为什么Spring没有将DELETE
映射到deleteUser
方法