我正在尝试为 spring @RequestMapping 注释创建 value 属性来像这样映射 url
/educationDistrict/308/action/resetAddressesForYear/1
and this
/educationDistrict/308/action/resetAddressesForYear
我有这个
@RequestMapping(value = "/{repository}/{id}/action/{methodName:[A-z]*}{v:.*}", method = RequestMethod.POST)
但第一个网址不匹配。
由于 spring-hateoas,我无法使用多值https://github.com/spring-projects/spring-hateoas/issues/186
春季 4.1.5
Add /**
在 URL 映射的末尾@RequestMapping
。您可以检索 URL 的最后部分,如下所示:
@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:我用过StringUtils
Apache Commons 查找最后一个索引/
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)