处理其余控制器端点中的非数值

问题描述 投票:0回答:0

当我使用非数值调用我的 API 时,% Spring 拒绝使用 400 http 状态代码的请求

 @RestController
 public Controller {
     @PostMapping
     public MyDto api(@RequestBody API request) {
     }
 }

 @Data
 public class API { 
       private Integer limit;
 }

例如发送:

POST http:\\localhost
Content-Type: application/json

 { limit: "%%" }

如何控制异常并在我的代码中处理它?例如让限制获得空值而不是拒绝请求?

java spring spring-boot error-handling spring-restcontroller
© www.soinside.com 2019 - 2024. All rights reserved.