4

How do I change my request mapping for dynamic urls? URLs might look like this:

Here's the working controller syntax when the url is in this format:

http://zz.zz.zz.com:8080/webapp/test?Id=2&maxrows=5

@RequestMapping(value = "/test", method = RequestMethod.GET)
public @ResponseBody void test(
    @RequestParam(value = "Id", required = true) String Id,
    @RequestParam(value = "maxrows", required = true) int maxrows
) throws Exception {
        System.out.println("Id: " + Id + " maxrows: " + maxrows);
}
AplusKminus
  • 1,542
  • 1
  • 19
  • 32
user3795951
  • 321
  • 2
  • 5
  • 7

1 Answers1

5

Try this:

@RequestMapping(value = "/test/{param1}/{param2}/{param3}")
public @ResponseBody void test(
    @RequestParam(value = "Id", required = true) String Id,
    @RequestParam(value = "maxrows", required = true) int maxrows,
    @PathVariable(value = "param1") String param1,
    @PathVariable(value = "param2") String param2,
    @PathVariable(value = "param3") String param3) {
    ...
}

For more information look at Spring Reference Documentation

Lukas Risko
  • 1,435
  • 14
  • 25