Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple mappings to the same method of a controller in Spring

I am trying to implement API versioning in my Spring application.

So I want to do something like this api_url/{version}/{params}

Lets say I have changed one of the endpoint functions, so I can map the new function to new url with new version. But I want the other unchanged functions to be mapped to both version urls, like api_url/{old-version}/{old-params} and api_url/{new-version}/{old-params}

So if I can implement something like this, it will help me from saving duplication of code in my Java class. How do I do this. Currently @RequestMapping only allows me to specify one value.

like image 254
Sambhav Sharma Avatar asked Feb 28 '14 11:02

Sambhav Sharma


1 Answers

You can use comma separated lists in the request mapping annotation.

@RequestMapping(value={"/url/{id}","/url2/{id}"}, method=RequestMethod.GET)
like image 80
Jaimie Whiteside Avatar answered Sep 23 '22 21:09

Jaimie Whiteside