Spring 如何在RequestMapping中使用正则表达式路径映射器变量?

Spring 如何在RequestMapping中使用正则表达式路径映射器变量?,spring,spring-mvc,Spring,Spring Mvc,我正在尝试使用请求映射器匹配URL,如下所示: http://localhost:9999/si/configs/some/path/on/the/server/file.xml 我有一个这样设置的控制器,但是findConfig方法的RequestMapping的值不正确。这是我的代码(除去所有无关的内容): @控制器 @请求映射(“/si/configs”) 公共类SIController{ @RequestMapping(value=“{path://***.xml}”,method=R

我正在尝试使用请求映射器匹配URL,如下所示:

http://localhost:9999/si/configs/some/path/on/the/server/file.xml
我有一个这样设置的控制器,但是
findConfig
方法的
RequestMapping
的值不正确。这是我的代码(除去所有无关的内容):

@控制器
@请求映射(“/si/configs”)
公共类SIController{
@RequestMapping(value=“{path://***.xml}”,method=RequestMethod.GET)
公共响应属性findConfig(@PathVariable(“path”)字符串路径){
//path arg的值应为:“/some/path/on/the/server/file.xml”
}
}
我知道Spring允许在路径匹配字符串中使用正则表达式,我试着遵循这个问题的建议:,但我似乎不能得到正确的答案

请求映射中应该包含什么


编辑

当我删除path变量并执行以下操作时:

    @RequestMapping(value = "/**/*.xml", method = RequestMethod.GET)
    public ResponseEntity<String> findConfig() {
    }
@RequestMapping(value=“/***/.xml”,method=RequestMethod.GET)
公共响应查找配置(){
}

已按预期调用我的控制器方法。因此,尝试将路径变量与spring不喜欢的wild Crad进行匹配是有道理的。

使用HttpServletRequest direclty怎么样

@RequestMapping(value = "/**/*.xml", method = RequestMethod.GET)
public ResponseEntity<String> findConfig(HttpServletRequest request) {
    String path = request.getServletPath()/getRequestURL()/getPathInfo()
    //I forget which one could give the correct part, maybe some parse operation needed
@RequestMapping(value=“/***/.xml”,method=RequestMethod.GET)
公共响应findConfig(HttpServletRequest请求){
字符串路径=请求。getServletPath()/getRequestURL()/getPathInfo()
//我忘了哪一个可以给出正确的部分,可能需要一些解析操作

}使用HttpServletRequest direclty怎么样

@RequestMapping(value = "/**/*.xml", method = RequestMethod.GET)
public ResponseEntity<String> findConfig(HttpServletRequest request) {
    String path = request.getServletPath()/getRequestURL()/getPathInfo()
    //I forget which one could give the correct part, maybe some parse operation needed
@RequestMapping(value=“/***/.xml”,method=RequestMethod.GET)
公共响应findConfig(HttpServletRequest请求){
字符串路径=请求。getServletPath()/getRequestURL()/getPathInfo()
//我忘了哪一个可以给出正确的部分,可能需要一些解析操作

}

如果您确定路径映射是正确的,请确保Spring内容协商没有去掉.xml后缀。当我调试时,xml后缀仍然存在。我只是不确定path变量内部的语法是否正确。编辑该问题以添加更多信息。我不确定PathVariable是否可以解决多个“/”如“foo/bar”。@Hippoom我不在乎是否使用PathVariable。我只想捕获请求映射中路径的最后一部分。如果您确定您的路径映射正确,请确保Spring内容协商没有去掉.xml后缀。调试时,xml后缀仍然存在。我只是不确定path变量内部的语法是否正确。编辑该问题以添加更多信息。我不确定PathVariable是否可以解决多个“/”如“foo/bar”。@Hippoom我不在乎是否使用PathVariable。我只想捕获请求映射中路径的最后一部分。