Alex Rivera | Logout

Spring MVC - Request mapping, two urls with two different parameters

Asked 2011-07-04T12:14:52.763
9

Is it possible in Spring to have one method with two different urls with different params for each method?

Below is pseudo code

@RequestMethod(URL1-param1, URL2-param2)
public void handleAction(@ModelAttribute("A") A a, ...) {
}

At the same time ULR1 is mapped in some other Controller as

@RequestMethod(URL1)
public void handleAction1(@ModelAttribute("A") A a, ...) {
}
Edit
Report

1 Answer

2

you can supply multiple mappings for your handler like this

@RequestMapping(value={"", "/", "welcome"})
public void handleAction(@ModelAttribute("A") A a, ...) { }

But if you want to use different parameters for each mapping, then you have to extract your method.

answered 2011-07-04T12:19:15.720

Your Answer