I've a request mapping that handles any string after the context e.g. www.example.com/anystring
I'm handling it as follows:
@RequestMapping(value="/{str}", method = RequestMethod.GET)
public String getApp(@PathVariable("str") String anyString, ModelMap model) {
//Do something
}
The problem is I've 2-3 URLs in my app where the URL is as follows: www.example.com/about, www.example.com/contact etc.
I wrote Request Mappings for them as follows:
@RequestMapping("/about")
public String getAboutPage() {
return "about";
}
But obviously, since I've already declared that any string should be handled by the getApp()
, the getAboutPage()
never gets executed.
How can I exclude /about
, /contact
etc from getApp()
mapping.
We can obviously add another keyword to the URL string, but that's not possible in my app use case.
Kindly help. :(
EDIT:
Should I just handle /about
, /contact
inside getApp()
like:
@RequestMapping(value="/{str}", method = RequestMethod.GET)
public String getApp(@PathVariable("str") String anyString, ModelMap model) {
if(anyString.equals("about")){
//do about related stuff
}
if(anyString.equals("contact")){
//do contact related stuff
}
//Do something
}
Is there a better way?