Refer to the exhibit.
Which option is a valid way to retrieve the account id? (Choose the best answer.)
Refer to the exhibit.
Which option is a valid way to retrieve the account id? (Choose the best answer.)
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.
A is the correct answer. Please refer to this: https://www.baeldung.com/spring-pathvariable#specifying-the-request-parameter-name
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
The answer is A. B will only be valid if the parameter name matches the path variable in the the URL.
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.