Card 02/ 06
All 6 cards
ExampleDifficulty: Intermediate1 min
@Valid Is What Makes It Run
The constraint annotations from the previous card do nothing by themselves. @Valid on the controller parameter is what tells Spring to actually check them before the method body runs.
@PostMapping("/rides")
ResponseEntity<String> createRide(@Valid @RequestBody RideRequest request) {
return ResponseEntity.ok("created: " + request);
}POST /rides, body {"pickup":"","passengers":0}
-> 400 Bad RequestAn empty pickup and a passengers of 0 both violate a constraint from the previous card, and the request never reaches createRide's body at all — Spring rejects it before your own code runs.