Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Web

Reply
 
Thread Tools Display Modes
  #1  
Old Feb 17th, 2009, 07:06 AM
Bjorn121 Bjorn121 is offline
Member
 
Join Date: Aug 2007
Posts: 84
Default 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:

Code:
@Controller
@RequestMapping("/path")
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.
Reply With Quote
  #2  
Old Feb 18th, 2009, 02:02 AM
Bjorn121 Bjorn121 is offline
Member
 
Join Date: Aug 2007
Posts: 84
Default

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.
Reply With Quote
  #3  
Old Feb 18th, 2009, 05:25 PM
Rossen Stoyanchev Rossen Stoyanchev is offline
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 317
Default

Yes this is a very basic scenario. Take a look at the Petclinic sample. RequestMapping annotations can be placed on methods.
Reply With Quote
  #4  
Old Feb 19th, 2009, 02:59 AM
Bjorn121 Bjorn121 is offline
Member
 
Join Date: Aug 2007
Posts: 84
Default

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.
Reply With Quote
  #5  
Old Feb 19th, 2009, 05:26 AM
NubKnacker NubKnacker is offline
Senior Member
 
Join Date: Oct 2008
Location: Delhi, India
Posts: 163
Default

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

You can also use regex to match the path.

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:18 PM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.