[英]How can I access path variables in my custom HandlerMethodArgumentResolver
considering this spring MVC handler method: 考虑到这个Spring MVC处理程序方法:
@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: 我的问题:我可以在这个解析器中访问
id
的值而无需手动解析URl:
public class PersonReslover implements HandlerMethodArgumentResolver { .. }
Using NativeWebRequest reference, which is accessible from resolveArgument() method of HandlerMethodArgumentResolver. 使用NativeWebRequest引用,可以从HandlerMethodArgumentResolver的resolveArgument()方法访问。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.