Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a simple DTO class field.
Spring Boot
private [1] name; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using entity class type instead of simple data type.
Using numeric types for text fields.
✗ Incorrect
The DTO field for a name is typically a String to hold text data.
2fill in blank
mediumComplete the code to convert an entity to a DTO in a method.
Spring Boot
return new UserDTO(entity.get[1]());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using getId() when the DTO expects a name.
Using unrelated getters like getDate().
✗ Incorrect
The method getName() retrieves the name from the entity to pass to the DTO.
3fill in blank
hardFix the error in the DTO constructor parameter type.
Spring Boot
public UserDTO([1] name) { this.name = name; } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Entity type instead of String.
Using generic Object type.
✗ Incorrect
The constructor should accept a String for the name, not an Entity or other type.
4fill in blank
hardFill both blanks to map entity fields to DTO fields correctly.
Spring Boot
dto.setName(entity.get[1]()); dto.setEmail(entity.get[2]());
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up field names like using getId() instead of getEmail().
Using setters with wrong getter calls.
✗ Incorrect
Mapping entity's getName() and getEmail() to DTO fields ensures data separation.
5fill in blank
hardFill all three blanks to create a DTO from entity fields with proper types.
Spring Boot
public record UserDTO([1] name, [2] email, [3] age) {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using long for age when int is sufficient.
Mixing types between name and email.
✗ Incorrect
UserDTO uses String for name and email, and int for age to keep simple data types.