Announcement Announcement Module
No announcement yet.
Map several requests to 1 controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Map several requests to 1 controller

    We're using annotations in our project and I was wondering if it's possible to map different paths to 1 controller.

    For instance, I have a Controller which handles a form. In that Controller we have 2 methods, namely setupForm (which is annotated with @RequestMapping( method = Request.GET)) and a method called processSubmit (which is annotated with @RequestMapping ( method = Request.POST )). At the top of our Controller, we have:

    public class CustomController
    Is there a way of providing another path to RequestMapping? Because we have 2 ways of requesting that form and each one should be handled by this Controller.

  • #2
    I should've changed the title of this thread to "Map several URL's to 1 controller", because that's what I want to do. Using a multi action controller is an option, but then I would have 2 methods which contain the same logic.


    • #3
      Yes this is a very basic scenario. Take a look at the Petclinic sample. RequestMapping annotations can be placed on methods.


      • #4
        I need to learn how to rephrase my issues :-). What I want to do is map several requests to 1 method, instead of 1 method per request.

        For instance /secure/user.html and /user.html should both be mapped to the GET-method.


        • #5
          @RequestMapping(value={"/secure/user.html", "/user.html"})

          You can also use regex to match the path.

          @RequestMapping(value={"/secure/user*.html", "/user*.html"}) etc..