Is it possible to have handleRequest function in a Spring Controller along with annotations for parameters?
I just started working with spring and set up a simple spring project in NetBeans. By default it doesn't seem to use annotations.
In one of my controllers I'd like to handle different clicks on the form. I have looked at some solutions and it seems like adding a parameter check could work:
@RequestMapping(params = "someAction")
public ModelAndView doSomeAction() {
However it looks like all of the requests are going to:
public class SetupController implements Controller {
@Override
public org.springframework.web.servlet.ModelAndView handleRequest(
HttpServletRequest hsr, HttpServletResponse hsr1) throws Except开发者_StackOverflowion {
Is there a way I can achieve the same effect without RequestMapping annotation?
It seams that you mixed the old (implements Controller) style with the new one annotation based style.
You can't (or at least should not) mix them, at least not for one class.
If you use Spring 3.x then I strongly recommend to use the Annotation based style.
@Controller
@RequestMapping("/whatever")
public class DemoController() {
@RequestMapping(params="x");
public ModelAndView doX() {
}
@RequestMapping(params="y");
public ModelAndView doY() {
}
}
To enable the Annotation Based style, you need at least this configuration settings:
<!-- Turns on support for mapping requests to Spring MVC @Controller methods
Also registers default Formatters and Validators for use across all
@Controllers -->
<mvc:annotation-driven conversion-service="applicationConversionService" />
精彩评论