Ana*_*hna 1 spring spring-mvc restful-url spring-restcontroller request-mapping
我想配置Spring将所有请求重定向到特定的Controller,而不管URL(长度和参数).我应该如何在RequestMapping注释中提供URL模式/正则表达式.我尝试使用下面的代码,但它无法正常工作.在这方面的任何帮助深表感谢.
@Controller
@RequestMapping("/*")
public class ServiceController {
@RequestMapping( method = RequestMethod.GET, value = "*" )
public void getProjectList(HttpServletRequest httpServletRequest,Model model){
}
}
Run Code Online (Sandbox Code Playgroud)
你需要@RequestMapping(method = RequestMethod.GET, value = "/**").
除URI模板外,
@RequestMapping注释还支持Ant样式的路径模式(例如,/myPath/*.do).
来自http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html:
映射使用以下规则匹配URL:
?匹配一个字符*匹配零个或多个字符**匹配路径中的零个或多个目录
| 归档时间: |
|
| 查看次数: |
2226 次 |
| 最近记录: |