添加控制器后,不允许在 Swagger UI 中使用该方法



我已将 Swagger 添加到项目中,它可以 https://zapodaj.net/217c8a0dcf348.png.html 工作。添加控制器后

@RestController(value = "/register")
public class RegisterRestController {
...
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> register(
        @RequestBody final RegisterDto registerDTO
) {
    this.userService.createUser(registerDTO);
    final HttpHeaders httpHeaders = new HttpHeaders();
    return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
}

招摇的 UI https://zapodaj.net/c60c3029b0905.png.html 停止工作。踢

"error": "Method Not Allowed",
"message": "Request method 'GET' not supported",
"status": "405"

我在stackoverflow上发现了一个类似的线程,但我不知道他如何帮助我。这个招摇是怎么回事?

您缺少与我添加的方法的映射"/register"

@PostMapping("/register")
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> register(
    @RequestBody final RegisterDto registerDTO
)

相关内容

最新更新