0
0
Spring Bootframework~10 mins

Response DTO for output 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 Response DTO class with a message field.

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

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
Drag options to blanks, or click blank then click option'
Aresponse
Bstatus
Cmessage
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different field name than the getter/setter methods.
Forgetting to declare the field.
2fill in blank
medium

Complete the code to add a constructor that sets the message field.

Spring Boot
public ResponseDTO([1] String message) {
    this.message = message;
}
Drag options to blanks, or click blank then click option'
Adouble
Bint
Cboolean
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong data type for the constructor parameter.
Forgetting to assign the parameter to the field.
3fill in blank
hard

Fix the error in the toString method to correctly return the message.

Spring Boot
@Override
public String toString() {
    return [1];
}
Drag options to blanks, or click blank then click option'
Amessage
BgetMessage()
Cthis.message
D"message"
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the string literal instead of the field value.
Returning the field directly without using getter.
4fill in blank
hard

Fill both blanks to create a ResponseDTO with a message and return it from a controller method.

Spring Boot
@GetMapping("/hello")
public ResponseDTO sayHello() {
    return new ResponseDTO([1]);
}

// The message to return is [2]
Drag options to blanks, or click blank then click option'
A"Hello, World!"
B"Goodbye"
C"Welcome"
D"Error"
Attempts:
3 left
💡 Hint
Common Mistakes
Using different messages in the code and comment.
Forgetting to put quotes around the string.
5fill in blank
hard

Fill all three blanks to create a ResponseDTO with a message, status, and data fields.

Spring Boot
public record ResponseDTO([1] String message, [2] int status, [3] Object data) {}
Drag options to blanks, or click blank then click option'
Afinal
Bprivate
Cpublic
Dstatic
Attempts:
3 left
💡 Hint
Common Mistakes
Using private or final which are not valid in record components.
Using static which is not allowed for record components.