2V0-72.22PSE · Question #50
Refer to the exhibit. Which option is a valid way to retrieve the account id? (Choose the best answer.)
The correct answer is A. Add @PathVariable("id") String accountId argument to the update() handler method. Option A is correct because the URL path variable is named {id} (as shown in the exhibit's mapping), but the Java parameter is named accountId - these names differ, so the explicit @PathVariable("id") binding is required to tell Spring which path segment to extract. Without the…
Question
Refer to the exhibit. Which option is a valid way to retrieve the account id? (Choose the best answer.)
Options
- AAdd @PathVariable("id") String accountId argument to the update() handler method.
- BAdd @PathVariable long accountId argument to the update() handler method.
- CAdd @RequestParam long accountId argument to the update() handler method.
- DAdd @RequestParam("id") String accountId argument to the update() handler method.
How the community answered
(24 responses)- A88% (21)
- C4% (1)
- D8% (2)
Explanation
Option A is correct because the URL path variable is named {id} (as shown in the exhibit's mapping), but the Java parameter is named accountId - these names differ, so the explicit @PathVariable("id") binding is required to tell Spring which path segment to extract. Without the explicit name, Spring cannot match accountId to {id} automatically.
Why the distractors fail:
- B uses
@PathVariable long accountIdwithout specifying("id"), so Spring attempts to find a path variable namedaccountId, which doesn't exist in the URL template - this causes a binding error. - C uses
@RequestParam, which reads from the query string (e.g.,?accountId=123), not from the URL path segment - wrong annotation entirely. - D also uses
@RequestParam, so despite correctly naming it"id", it still looks in the query string instead of the path - same fundamental mistake as C.
Memory tip: Think Path → @PathVariable, Query string (?) → @RequestParam. And whenever your Java parameter name doesn't exactly match the {placeholder} in the URL, you must name it explicitly: @PathVariable("placeholder-name").
Topics
Community Discussion
No community discussion yet for this question.