0

Is is possible to delegate different @RequestMapping methods by evaluation get-query parameter?

Example: if I call localhost:8080/cars?format=csv I want to invoke the first method.

But if I call localhost:8080/cars?format=anyothervalue I'd like to invoke the second method. Is that possible in spring using @RequestParams?

@RestController
public class MyServlet {
    @RequestMapping("/cars", {format == 'csv'})
    public Response doGetCsv(@RequestParam format) {

    }

    @RequestMapping("/cars", {format == 'xml'})
    public Response doGetOthers(@RequestParam format) {

    }
}
4
  • just off the bat: format == 'csv' and format != null is ambiguous. For the container both methods are valid if format is 'csv' Commented Jun 21, 2017 at 14:23
  • @efekctive thanks for the hint, I modified my example. Commented Jun 21, 2017 at 14:29
  • not a problem. you're welcome Commented Jun 21, 2017 at 14:30
  • Why don't you use accept headers? Commented Jun 22, 2017 at 8:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.