Bird
0
0

Given the controller class below, what is the full URL path to access the getUser() method?

medium📝 component behavior Q13 of 15
Spring Boot - REST Controllers
Given the controller class below, what is the full URL path to access the getUser() method?
@RequestMapping("/api")
public class UserController {
  @RequestMapping("/user")
  public String getUser() { return "user"; }
}
A/user
B/user/api
C/api
D/api/user
Step-by-Step Solution
Solution:
  1. Step 1: Identify class-level base path

    The class has @RequestMapping("/api"), so all method paths start with /api.
  2. Step 2: Append method-level path

    The method getUser() has @RequestMapping("/user"), so the full path is /api + /user = /api/user.
  3. Final Answer:

    /api/user -> Option D
  4. Quick Check:

    Base path + method path = full URL [OK]
Quick Trick: Combine class and method paths with slashes [OK]
Common Mistakes:
  • Ignoring class-level path
  • Mixing order of paths
  • Missing leading slash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes