I'm using validators in my spring controllers. If @RequestParam
is required there is no problem, i can check String with @NotBlank
. But if @RequestParam
is optional, i can't use it with @NotBlank
, because this parameter is optional and sometimes can be null.
I want to validate @NotBlank
if String is not null. Is there any constraint help me?
@RequestParam @NotBlank String name
working perfectly. I have problem with required=false
if client don't send optional description parameter, validation fails.
@PatchMapping("/role/{id}")
public ResponseEntity<?> updateRole(HttpServletRequest request, @PathVariable @Positive Integer id,
@RequestParam @NotBlank String name,
@RequestParam(required = false) @NotBlank String description)
I want to validate @NotBlank
if description is not null
.
`@RequestParam(required = false) @NotBlank String description`
If i use like that, i got "Input validation failed!".