I\'m trying to make value atribute for spring @RequestMapping annotation to map url like this
/educationDistrict/308/action/resetAddressesForYear/1
Add /**
at the end of the URL mapping in @RequestMapping
. And you can retrieve last part of the URL as below:
@RequestMapping(value = "/{repository}/{id}/action/{methodName:[A-z]*}{v:.*}/**", method = RequestMethod.GET)
public ModelAndView welcome(@PathVariable("methodName") String name, HttpServletRequest request) {
String mvcPath = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
int index = StringUtils.lastIndexOf(mvcPath, "/");
System.out.println("Method name - " + name);
System.out.println("Rest of the URL - " + mvcPath.substring(index+1));
ModelAndView model = new ModelAndView();
model.setViewName("index");
model.addObject("name", mvcPath);
return model;
}
Note: I have used StringUtils
Apache Commons to find the last index of /
.