我有这个请求映射:
@RequestMapping(value = "/route/to-{destination}-from-{departure}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
我想添加 RequestMapping:
@RequestMapping(value = "/route/to-{destination}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
因此它可以服务所有“不出发”的航线。然而,这会产生冲突,因为“/route/to-destination-from-departure”url 实际上也与第二个 RequestMapping 匹配......
很公平,所以我的解决方案是指定一个正则表达式:
@RequestMapping(value = "/route/to-{destination:^((?!-from-).)+}.html", method = {RequestMethod.GET, RequestMethod.HEAD})
因此,如果“destination”包含“-from-”,RequestMapping 将不匹配。
而且……这不起作用!第一个 RequestMapping 成功提供了 url“/route/to-barcelona-from-paris.html”,但根本没有提供 url“/route/to-barcelona.html”...我缺少什么?
注意:我不想使用java解决方案,例如有一个“/route/to-{destination}”RequestMapping,然后检查“destination”是否包含“-from-”..:)另外,我不能改变这些路线是因为 SEO...