Reputation: 321
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);
}
Upvotes: 4
Views: 12452
Reputation: 1489
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
Upvotes: 5