我的控制器中有以下请求映射,但是当我点击/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){
.....
}
答案 0 :(得分:1)
我不是百分之百确定@RequestMapping注释支持正则表达式的外观但尝试从请求映射注释中排除“united-states”和“canada”getDetailsInCity()
@RequestMapping(value = "/{country:^(?!.*canada)(?!.*united-states).*$}/{city}")
public String getDetailsInCity(@PathVariable String country,@PathVariable String city){
.....
}
我从这里得到了正则表达式:How to negate specific word in regex?