0
0
Spring Bootframework~10 mins

DTO validation 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 add a validation annotation that ensures the 'name' field is not empty.

Spring Boot
public class UserDTO {
    @[1]
    private String name;

    // getters and setters
}
Drag options to blanks, or click blank then click option'
ASize
BNotEmpty
CEmail
DMin
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Size without specifying min value
Using @Email for a name field
Using @Min which is for numbers
2fill in blank
medium

Complete the code to validate that the 'email' field contains a valid email format.

Spring Boot
public class UserDTO {
    @[1]
    private String email;

    // getters and setters
}
Drag options to blanks, or click blank then click option'
ANotNull
BPattern
CEmail
DNotBlank
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotNull which only checks for null, not format
Using @Pattern without regex
Using @NotBlank which only checks for empty strings
3fill in blank
hard

Fix the error in the code by adding the correct annotation to ensure 'age' is at least 18.

Spring Boot
public class UserDTO {
    @[1]
    private int age;

    // getters and setters
}
Drag options to blanks, or click blank then click option'
AMax(18)
BPositive
CSize(min=18)
DMin(18)
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Max instead of @Min
Using @Size which is for strings or collections
Using @Positive which only checks greater than zero
4fill in blank
hard

Fill both blanks to create a DTO field 'password' that must be at least 8 characters and not blank.

Spring Boot
public class UserDTO {
    @[1]
    @[2](min = 8)
    private String password;

    // getters and setters
}
Drag options to blanks, or click blank then click option'
ANotBlank
BNotNull
CSize
DPattern
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotNull instead of @NotBlank
Using @Pattern without regex
Using @Size without min parameter
5fill in blank
hard

Fill all three blanks to create a DTO field 'username' that is not null, has length between 5 and 15, and matches only letters and digits.

Spring Boot
public class UserDTO {
    @[1]
    @[2](min = 5, max = 15)
    @[3](regexp = "^[a-zA-Z0-9]+$")
    private String username;

    // getters and setters
}
Drag options to blanks, or click blank then click option'
ANotNull
BSize
CPattern
DNotBlank
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotBlank instead of @NotNull
Omitting max in @Size
Using wrong regex in @Pattern