Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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
Java Spring@RequestMapping";“不包含”;正则表达式_Java_Regex_Spring_Request Mapping - Fatal编程技术网

Java Spring@RequestMapping";“不包含”;正则表达式

Java Spring@RequestMapping";“不包含”;正则表达式,java,regex,spring,request-mapping,Java,Regex,Spring,Request Mapping,我有这样的要求: @RequestMapping(value = "/route/to-{destination}-from-{departure}.html", method = {RequestMethod.GET, RequestMethod.HEAD}) @RequestMapping(value = "/route/to-{destination}.html", method = {RequestMethod.GET, RequestMethod.HEAD}) 我想补充一点,那就是

我有这样的要求:

@RequestMapping(value = "/route/to-{destination}-from-{departure}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
@RequestMapping(value = "/route/to-{destination}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
我想补充一点,那就是请求映射:

@RequestMapping(value = "/route/to-{destination}-from-{departure}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
@RequestMapping(value = "/route/to-{destination}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
因此,它可以服务于所有“不出发”路线。然而,这会造成冲突,因为“/route/to destination from exchange”url实际上也与第二个RequestMapping匹配。。。 很公平,所以我的解决方案是指定一个正则表达式:

@RequestMapping(value = "/route/to-{destination:^((?!-from-).)+}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
因此,如果“目的地”包含“-from-”,则RequestMapping将不匹配

而且。。。它不起作用!url“/route/to barcelona from paris.html”由第一个RequestMapping成功提供,但url“/route/to barcelona.html”根本不提供。。。我错过了什么

注意:我不想使用java解决方案,例如使用单个“/route/to-{destination}”请求映射,然后检查“destination”是否包含“-from-”。:)此外,由于搜索引擎优化,我无法更改这些路线…

尝试使用此:->

{目的地:^(?!from)+}

{目的地:^((?!-from-)+}

您可以使用

"/route/to-{destination:(?!.*-from-).+}.html"
^
锚点将搜索字符串的开头,并将在此处失败任何匹配

(?!.-from-
负前瞻将使任何包含
-from-
的输入在任何0+字符(换行字符除外)之后失败


+
模式将消耗除换行符以外的所有1个或多个字符到行尾。

尝试
{destination:(?!.-from-)+}.html
{destination:(?!.-from-[^\/]+}.html
@WiktorStribiżew{destination:(?!.-from-)+}!你让我开心,非常感谢!(“{目的地:(?!.-from-[^\/]+}”没有)作为奖励,这里有一个关于你的漫画哈哈:两个都试过了,但都没用!Wiktor Stribiżew的“{destination:(?!.-from-).+}.html”起作用了,所以我们有了解决方案!谢谢你的帮助!