considering this spring MVC handler method:
@RequestMapping(value = "/profile/{id}", method = RequestMethod.GET)
public String displayProfile(Person person, ModelMap model) { ... }
my question: can I access the value of id
in this resolver without having to parse the URl manually:
public class PersonReslover implements HandlerMethodArgumentResolver { .. }
Using NativeWebRequest reference, which is accessible from resolveArgument() method of HandlerMethodArgumentResolver.
For example:
private Map<String, String> getPathVariables(NativeWebRequest webRequest) {
HttpServletRequest httpServletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
return (Map<String, String>) httpServletRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With