0
0
Spring Bootframework~5 mins

@RequestMapping for base paths in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @RequestMapping annotation in Spring Boot?

@RequestMapping is used to map web requests to specific handler classes or methods in Spring Boot. It defines the URL path and HTTP method that a controller or method will respond to.

Click to reveal answer
beginner
How does <code>@RequestMapping</code> work when placed on a class level?

When @RequestMapping is placed on a class, it sets a base path for all the methods inside that class. Each method's path is appended to this base path.

Click to reveal answer
beginner
Example: What URL will the method respond to if the class has <code>@RequestMapping("/api")</code> and the method has <code>@RequestMapping("/users")</code>?

The method will respond to requests at /api/users. The class-level path /api is combined with the method-level path /users.

Click to reveal answer
intermediate
Can @RequestMapping specify HTTP methods? How?

Yes. You can specify HTTP methods like GET, POST, etc., using the method attribute, for example: @RequestMapping(value = "/path", method = RequestMethod.GET).

Click to reveal answer
beginner
What happens if you omit the path in <code>@RequestMapping</code> at the class level?
<p>If omitted, the class does not set a base path, so method-level paths are treated as absolute from the root context.</p>
Click to reveal answer
What does @RequestMapping("/app") on a class do?
ASets a base URL path for all methods in the class
BMaps only GET requests to the class
CDefines a response type for the class
DDisables all mappings in the class
If a method has @RequestMapping("/list") and the class has @RequestMapping("/api"), what is the full path?
A/api
B/list
C/api/list
D/list/api
How do you specify that a method should only handle POST requests with @RequestMapping?
AhttpMethod = POST
Bmethod = "POST"
Ctype = POST
Dmethod = RequestMethod.POST
What happens if no @RequestMapping is on the class but methods have paths?
AMethods do not respond to any requests
BMethods respond at root-level paths
CClass path defaults to "/default"
DApplication throws an error
Which annotation is a shortcut for @RequestMapping with GET method?
A@GetMapping
B@PostMapping
C@PutMapping
D@DeleteMapping
Explain how @RequestMapping at the class level affects the URL paths of methods inside the class.
Think about how a street address works with a building and apartment number.
You got /3 concepts.
    Describe how to restrict a method to handle only POST requests using @RequestMapping.
    Consider how a door might only open for certain visitors.
    You got /3 concepts.