How to validate the size of @RequestParam of type List

前端 未结 3 1107
走了就别回头了
走了就别回头了 2021-01-13 21:53

I\'m creating a Spring-Boot microservice REST API that expects @RequestParam of type List. How can I validate that the list contains

3条回答
  •  滥情空心
    2021-01-13 22:19

    As per Bean Validator 2.0, Hibernate Validator 6.x, you can use constraints directly on parameterized type.

    @GetMapping(path = "/myApi", produces = { APPLICATION_JSON_VALUE })
    public ResponseEntity> getSomething(@RequestParam(value = "programEndTime", required = false) List<@Size(min = 1, max = 2) String> programEndTimes)
    

    For more information, check out Container element constraints.

提交回复
热议问题