Complete the code to define a simple Request DTO class with a private field and its getter.
public class UserRequestDTO { private String [1]; public String getUsername() { return username; } }
The field name must match the getter method name. Here, the getter is getUsername(), so the field should be username.
Complete the code to add a setter method for the field in the Request DTO.
public void [1](String username) {
this.username = username;
}Setter methods in Java follow the pattern setFieldName. Here, the field is username, so the setter is setUsername.
Fix the error in the annotation to make this class a valid Request DTO in Spring Boot.
@[1] public class UserRequestDTO { private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
The @Data annotation from Lombok generates getters and setters automatically, making the DTO concise and valid.
Fill both blanks to create a Request DTO with validation annotations for a non-empty username.
import jakarta.validation.constraints.[1]; public class UserRequestDTO { @[2](message = "Username cannot be empty") private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
The @NotBlank annotation ensures the username is not null and not empty after trimming spaces.
Fill all three blanks to create a Request DTO with username and age fields, including validation for non-empty username and minimum age 18.
import jakarta.validation.constraints.[1]; import jakarta.validation.constraints.[2]; public class UserRequestDTO { @[3](message = "Username cannot be empty") private String username; @Min(18) private int age; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
Import NotBlank for username validation and Min for age validation. The username field uses @NotBlank.