0
0
Spring Bootframework~10 mins

Request DTO for input in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a simple Request DTO class with a private field and its getter.

Spring Boot
public class UserRequestDTO {
    private String [1];

    public String getUsername() {
        return username;
    }
}
Drag options to blanks, or click blank then click option'
Aname
Busername
CuserName
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field name that does not match the getter method name.
Using uppercase letters at the start of the field name.
2fill in blank
medium

Complete the code to add a setter method for the field in the Request DTO.

Spring Boot
public void [1](String username) {
    this.username = username;
}
Drag options to blanks, or click blank then click option'
AupdateUsername
BsetUser
CgetUsername
DsetUsername
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' in the method name.
Using a method name that does not match the field name.
3fill in blank
hard

Fix the error in the annotation to make this class a valid Request DTO in Spring Boot.

Spring Boot
@[1]
public class UserRequestDTO {
    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
Drag options to blanks, or click blank then click option'
AData
BEntity
CRequestBody
DRestController
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Entity which is for database entities.
Using @RestController which is for controllers.
Using @RequestBody which is for method parameters.
4fill in blank
hard

Fill both blanks to create a Request DTO with validation annotations for a non-empty username.

Spring Boot
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;
    }
}
Drag options to blanks, or click blank then click option'
ANotBlank
BNotNull
CSize
DEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotNull which allows empty strings.
Using @Email which is for email format validation.
5fill in blank
hard

Fill all three blanks to create a Request DTO with username and age fields, including validation for non-empty username and minimum age 18.

Spring Boot
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;
    }
}
Drag options to blanks, or click blank then click option'
ANotBlank
BMin
CNotNull
DSize
Attempts:
3 left
💡 Hint
Common Mistakes
Importing @NotNull instead of @NotBlank for username.
Not importing @Min for age validation.