spring mvc @PathVariable / 带斜杠方式获取

一、遇上这个问题,百度google了一下,抄袭里面的内容,可以实现,在此备忘


@RequestMapping(value = "/download/{value1}/**", method = RequestMethod.GET)
public void getValue(@PathVariable String value1, HttpServletRequest request) throws CommonException {
String value = extractPathFromPattern(request);
}




private String extractPathFromPattern(final HttpServletRequest request) {
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
}


猜你喜欢

转载自blog.csdn.net/jiangxuexuanshuang/article/details/51720362