minion
minion

Reputation: 4353

Spring Request Mapping complication

I have the following request mappings in my controllers, but when i hit /united-states/georgia it always goes to the method mapped with {country/city} even though . How to force it to go to the united-states method. Any suggestion would be appreciated.

@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){
.....
}

Upvotes: 0

Views: 192

Answers (1)

FriedSaucePots
FriedSaucePots

Reputation: 1352

I'm not 100% sure @RequestMapping annotations support regex lookarounds but try excluding "united-states" and "canada" from the request mapping annotation for getDetailsInCity()

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

I got the regex from here: How to negate specific word in regex?

Upvotes: 1

Related Questions