Bird
0
0

Given the controller below, what URL path will trigger the getDetails() method?

medium📝 component behavior Q4 of 15
Spring Boot - REST Controllers
Given the controller below, what URL path will trigger the getDetails() method?
 @RestController
 @RequestMapping("/orders")
 public class OrderController {
   @RequestMapping("/details")
   public String getDetails() { return "Order Details"; }
 }
A/details/orders
B/orders/details
C/orders
D/details
Step-by-Step Solution
Solution:
  1. Step 1: Identify class-level base path

    The class has @RequestMapping("/orders"), so all methods are under "/orders" base path.
  2. Step 2: Identify method-level path

    The method has @RequestMapping("/details"), which appends to the base path.
  3. Step 3: Combine paths

    Full URL path is "/orders/details".
  4. Final Answer:

    /orders/details -> Option B
  5. Quick Check:

    Class path + method path = full URL [OK]
Quick Trick: Combine class and method paths for full URL [OK]
Common Mistakes:
  • Swapping order of paths
  • Using only method path as URL
  • Ignoring class-level @RequestMapping

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes