Spring @请求映射正则表达式
我试图将spring@RequestMapping注释的值atribute映射到如下urlSpring @请求映射正则表达式,spring,spring-mvc,Spring,Spring Mvc,我试图将spring@RequestMapping注释的值atribute映射到如下url /educationDistrict/308/action/resetAddressesForYear/1 还有这个 /educationDistrict/308/action/resetAddressesForYear 我有这个 @RequestMapping(value = "/{repository}/{id}/action/{methodName:[A-z]*}{v:.*}", method
/educationDistrict/308/action/resetAddressesForYear/1
还有这个
/educationDistrict/308/action/resetAddressesForYear
我有这个
@RequestMapping(value = "/{repository}/{id}/action/{methodName:[A-z]*}{v:.*}", method = RequestMethod.POST)
但第一个url不匹配
我不能使用多值,因为spring hateoas
spring 4.1.5在
@RequestMapping
中的URL映射末尾添加/**
。您可以检索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;
}
注意:我使用了StringUtils
apachecommons来查找/
的最后一个索引