Spring 3 RequestMapping:获取路径值 [英] Spring 3 RequestMapping: Get path value

查看:546
本文介绍了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=1restOfTheUrl=/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆