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);
}

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.