Complete the code to add input validation annotation for a non-empty string in Spring Boot.
@NotBlank(message = "Name cannot be empty") private String [1];
The @NotBlank annotation is used to ensure the string is not empty or null. Here, it is applied to the username field to validate user input.
Complete the code to validate that an integer input is at least 18 in Spring Boot.
@Min(value = [1], message = "Age must be at least 18") private int age;
The @Min annotation ensures the integer value is not less than the specified minimum. Here, it validates that age is at least 18.
Fix the error in the code to correctly validate an email input in Spring Boot.
@Email(message = "Invalid email format") private String [1];
The @Email annotation validates that the string is a valid email format. It should be applied to the emailAddress field.
Fill both blanks to create a validated DTO class with a non-null name and age at least 21.
public class UserDTO { @[1](message = "Name is required") private String name; @[2](value = 21, message = "Must be at least 21") private int age; }
@NotBlank ensures the name is not null or empty. @Min(21) ensures age is at least 21.
Fill all three blanks to create a Spring Boot controller method that validates input and returns a response.
@PostMapping("/register") public ResponseEntity<String> registerUser(@Valid @RequestBody [1] user) { if (user.getAge() [2] 18) { return ResponseEntity.status(HttpStatus.[3]).body("User too young"); } return ResponseEntity.ok("User registered"); }
The method accepts a validated UserDTO object. It checks if age is less than 18. If so, it returns a 403 FORBIDDEN status with a message.