Spring 3 RequestMapping:获取路径值 [英] Spring 3 RequestMapping: Get path value
本文介绍了Spring 3 RequestMapping:获取路径值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在解析requestMapping
@PathVariable
值之后是否有获取完整路径值的方法?
Is there a way to get the complete path value after the requestMapping
@PathVariable
values have been parsed?
即:
/{id}/{restOfTheUrl}
应该能够将/1/dir1/dir2/file.html
解析为id=1
和restOfTheUrl=/dir1/dir2/file.html
That is:
/{id}/{restOfTheUrl}
should be able to parse /1/dir1/dir2/file.html
into id=1
and restOfTheUrl=/dir1/dir2/file.html
任何想法都会受到赞赏.
Any ideas would be appreciated.
推荐答案
URL的不匹配部分作为名为HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
的请求属性公开:
Non-matched part of the URL is exposed as a request attribute named HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
:
@RequestMapping("/{id}/**")
public void foo(@PathVariable("id") int id, HttpServletRequest request) {
String restOfTheUrl = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
...
}
这篇关于Spring 3 RequestMapping:获取路径值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文