Exam 2v0-7222 All QuestionsBrowse all questions from this exam
Question 13

Refer to the exhibit.

Which option is a valid way to retrieve the account id? (Choose the best answer.)

    Correct Answer: A

    To retrieve the account ID from the path in a Spring controller, you should use the @PathVariable annotation with the variable name matching the placeholder in the URL. The placeholder in the URL is {id}, so you need to bind this to a method parameter. Using @PathVariable("id") with a String type correctly binds the value from the URL to the method parameter. This allows the update method to access the account ID directly from the path variable.

Discussion
AzuniOption: A

A is the correct answer. Please refer to this: https://www.baeldung.com/spring-pathvariable#specifying-the-request-parameter-name

IYONISSIOOption: B

The correct option is B. Add @PathVariable long accountId argument to the update() handler method. The @PathVariable annotation is used to bind a path variable from the request URI to a parameter in the handler method. In this case, the path variable is id, and the type is long. This means that the account id will be passed to the update() handler method as a long value

Azuni

The answer is A. B will only be valid if the parameter name matches the path variable in the the URL.

2211094Option: B

Be careful here, to me this question is one of very tricky question. Answer is B and not A because A forces data type conversion from string to Integer/long.