This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi all, I want to map a request in my controller. The thing is I can have anything in the request url prefixed with a constant say "java". I should write a request mapping which will be generic for all urls containing java
I wrote these mappingsNow if I have another url like this
I should definitely have another mapping like thisNow as the number of folders increase I have to keep on add @RequestMappings. Can I have a generic mapping instead of all these like a regular expression style. I tried the following but failedI could not figure out the logic. Is this possible actually?
Bill Gorder wrote:is your resource on the file system like a file and the path is where on the file system it is located? What are you trying to accomplish?
I would get rid of the .do stuff too that is kind of old school now and you don't typically see it anymore in new applications.
Actually I am having a controller which which redirects/forwards request to appropriate pages.
My folder structure is WEB-INF/jsp/static/java/<<sub-folder1>>/<<sub-folder2>>/ so on
Here <<sub-folder1>> has some pages in it. <<sub-folder2>> also has some pages in it. Again <<sub-folder2>> can have even more folders in it. Say <<sub-folder3>>. Or say let us stop at <<sub-folder3>> only. <<sub-folder3>> has some pages in it.
To redirect/forward to a page under these folders I have to write 4 @RequestMapping like thisMy question is can I group these four request mappings in to one? I tried using regular expressions but failed. I want only one @RequestMapping which should be called for
I want a request mapping such that it should be hit with any path starting with java/<<anything>>. I tried java/* It is only working for java/page.do, java/page2.do and so on. When I try java/sub-folder1/page1.do this request mapping is not being hit.
I hope this will explain well about what I want to accomplish.
Looking at the docs RequestMapping does not support regex. It does support ant style globs. You can use Regex however inside of your URI templates for example
URI template using regex
Request Mapping using ant style globs
This is actually demonstrated in the spring reference manual.
Now to your other question, even if it were possible I would lean towards one of the other approaches for a couple reasons:
1. Regex is harder to read and maintain
2. Regex is more error prone you may inadvertently match something you don't mean to
3. Regex does not add any real value imo, you can still use just one RequestMapping with either of the other approaches from the last post.
I searched few sites and came to know that many already tried what I am trying. I came to know that there is no property to define that a path variable is optional. The only way is to have two @RequestMappings or introduce request parameters like this.I hope this will help future readers. Good day.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com