Recall & Review
beginner
What is the purpose of @RequestMapping in Spring Boot?
It is used to map HTTP requests to handler methods in controller classes, specifying the URL path and HTTP method.
Click to reveal answer
beginner
How do you specify that a method should handle only GET requests for path '/hello'?
Use @RequestMapping(value = "/hello", method = RequestMethod.GET) above the method.
Click to reveal answer
intermediate
What annotation shortcut can be used instead of @RequestMapping(method = RequestMethod.POST)?
You can use @PostMapping to map POST requests more simply.
Click to reveal answer
intermediate
Can @RequestMapping map multiple HTTP methods to the same method? How?
Yes, by setting method attribute to an array, e.g., method = {RequestMethod.GET, RequestMethod.POST}.
Click to reveal answer
beginner
What happens if you omit the method attribute in @RequestMapping?
The method will handle requests of all HTTP methods for the specified path.
Click to reveal answer
Which annotation maps a method to handle HTTP GET requests for path '/users'?
✗ Incorrect
The @GetMapping annotation is a shortcut for @RequestMapping with method GET.
How do you map a method to handle both GET and POST requests on path '/data'?
✗ Incorrect
Setting method to an array of RequestMethod enums allows multiple HTTP methods.
What is the default HTTP method if you use @RequestMapping("/path") without method attribute?
✗ Incorrect
Without specifying method, the mapping applies to all HTTP methods.
Which annotation is NOT a shortcut for a specific HTTP method in Spring Boot?
✗ Incorrect
@RequestMapping is general and requires method attribute to specify HTTP method.
How do you map a method to handle DELETE requests on path '/item/{id}'?
✗ Incorrect
@DeleteMapping is the shortcut for DELETE HTTP method mapping.
Explain how to map a Spring Boot controller method to handle POST requests at path '/submit'.
Think about the annotation and method attribute for POST.
You got /3 concepts.
Describe what happens if you use @RequestMapping("/test") without specifying the HTTP method.
Consider default behavior of @RequestMapping.
You got /3 concepts.