Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex @RequestMapping中的正则表达式_Regex_Spring Mvc - Fatal编程技术网

Regex @RequestMapping中的正则表达式

Regex @RequestMapping中的正则表达式,regex,spring-mvc,Regex,Spring Mvc,我被以下几点困住了。假设我有一个像 http://localhost:8080/a/somename-anyothername-onemorename-aAttributeId.html http://localhost:8080/a/anyothername-onemorename-aAttributeId.html http://localhost:8080/a/anyothername-onemorename-anyothername-anyothername-aAttributeId.h

我被以下几点困住了。假设我有一个像

http://localhost:8080/a/somename-anyothername-onemorename-aAttributeId.html
http://localhost:8080/a/anyothername-onemorename-aAttributeId.html
http://localhost:8080/a/anyothername-onemorename-anyothername-anyothername-aAttributeId.html
...
通常,url可能有许多部分。我的目标是将上面url的属性ID部分设置为@RequestMapping中的变量,如下所示

@Controller
@RequestMapping(value = "/**/a")
public class ProductPageController extends AbstractPageController
{

@RequestMapping(value = "/{attributeId:(?:[-a])(?!.*(?:[-a])).*}.html", method =      RequestMethod.GET)
     public String requestHandler(@PathVariable("attributeId") final String attributeId,   final Model model) {
          //method body
     }
}    
} 
我的问题是我的正则表达式有什么错?我是否应该以某种方式拆分正则表达式以转义aAttributeId.html部分之前的所有内容,如下所示:

@RequestMapping(value = "/{unused:*.}{productCode:(?:[-a])(?!.*(?:[-a])).*}.html", method = RequestMethod.GET)
@RequestMapping(value = "/**{attributeId:a(?:[^-]+)}.html", method = RequestMethod.GET)
谢谢你的建议

更新:问题的答案

最终映射如下所示:

@RequestMapping(value = "/{unused:*.}{productCode:(?:[-a])(?!.*(?:[-a])).*}.html", method = RequestMethod.GET)
@RequestMapping(value = "/**{attributeId:a(?:[^-]+)}.html", method = RequestMethod.GET)
那么:

-a([^-]+)\.html

注:我不知道spring语法。

@CyrilDeba:有一个拼写错误,现在可以了吗?我接受了你的答案,但我对它做了一些修改(请参阅更新的问题)。谢谢!