I cannot validate a string type path variable in Spring Boot app. I tried the suggestions mentioned on How to validate Spring MVC @PathVariable values?, but not working. So, do I have to create a custom validator just for validating a @PathVariable value?
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotNull;
@RestController
@Validated
@RequestMapping("/api/v1")
public class DataController {
@GetMapping("/employees/{code}")
public ResponseEntity<ApiResponse<List<Employee>>> findAllByCode(
// @PathVariable("code") @Valid @NotBlank String code) {
@PathVariable("code") @NotBlank String code) {
// ...
}
}
Any idea about the solution?