0

我的控制器中有以下请求映射,但是当我点击它时/united-states/georgia,它总是转到映射的方法,{country/city}即使 . 如何强迫它走美国的方法。任何建议将不胜感激。

@RequestMapping(value = "/{country:united-states|canada}/{state}")
public String getCitites(@PathVariable String country,@PathVariable String state){
.....
}

@RequestMapping(value = "/{country}/{city}")
public String getDetailsInCity(@PathVariable String country,@PathVariable String city){
.....
}
4

1 回答 1

1

我不是 100% 确定 @RequestMapping 注释支持正则表达式外观,但尝试从 getDetailsInCity() 的请求映射注释中排除“美国”和“加拿大”

@RequestMapping(value = "/{country:^(?!.*canada)(?!.*united-states).*$}/{city}")
public String getDetailsInCity(@PathVariable String country,@PathVariable String city){
.....
}

我从这里得到了正则表达式:How to negate specific word in regex?

于 2015-04-20T15:27:47.263 回答