Enabling validation on ;the controller method

It's very simple to enable validation on the controller method. The following snippet shows an example:

    @RequestMapping(method = RequestMethod.POST,     path = "/users/{name}/todos")    ResponseEntity<?> add(@PathVariable String name    @Valid @RequestBody Todo todo) {

The @Valid(package javax.validation) annotation is used to mark a parameter for validation. Any validation that is defined in the Todo bean is executed before the add method is executed.

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.