0

I need to find an approach for below problem.

Need to configure below URLs in spring controllers

/karnataka/playgrounds
/karnataka/banglore-playgrounds
/karnataka/airport-road-banglore-playgrounds
/karnataka/chinnaswamy-stadium-airport-road-banglore

@PathVariables here are

{state} = karnataka
{city} = banglore
{locationType} =  playgrounds
{location} = airport-road
{pointName} = chinnaswamy-stadium

I have these 5 variables. There can be any value for state, city, location type, location, point name (allowed values/list can be stored in properties or in db).

My question is how can I configure above mentioned URLs with these path variables in spring controllers?

Tried some request mapping but not able to set priority.

@RequestMapping(value = {"/{state}/{locationType}"})
@RequestMapping(value = {"/{state}/{city}{type}"})
@RequestMapping(value = {"/{state}/{location}-{city}-{type}"})
@RequestMapping(value = {"/{state}/{pointName}-{location}-{city}"})

Also there '-' problem. There can be '-' between two Path Variables and there can be '-' between a single variable like airport-road. So some already allowed values can be solution for this.

Please provide a solution to this.

Thanks in advance!

pankaj
  • 1,643
  • 4
  • 22
  • 35
  • 1
    how about having a single `PathVariable` and then parse it within the method for different values? – sidgate Oct 30 '15 at 12:33
  • Can you change the mappings? Having "-" in values as well as in mapping definitions the way you have them is definitely a problem. – jny Oct 30 '15 at 13:10
  • Not a good idea to split it in this fashion. You can just as easily construct an Object containing all these parameters and send that one. Check values which you require and then start processing. Avoid such ambiguous, commonly used String based controller mappings, the developer after you will condemn you to hell for that. – We are Borg Oct 30 '15 at 13:40

0 Answers0