1

我想将 Spring 配置为将所有请求重定向到特定的控制器,而不考虑 URL(长度和参数)。我应该如何在 RequestMapping 注释中给出 URL 模式/正则表达式。我尝试使用下面的代码,但它不起作用。非常感谢这方面的任何帮助。

    @Controller
    @RequestMapping("/*")
    public class ServiceController {
        @RequestMapping( method = RequestMethod.GET, value = "*" )
        public void getProjectList(HttpServletRequest httpServletRequest,Model model){

        }
    }
4

2 回答 2

7

你需要@RequestMapping(method = RequestMethod.GET, value = "/**").

来自http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-patterns

除了 URI 模板,@RequestMapping注解还支持Ant 样式的路径模式(例如,/myPath/*.do)。

来自http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html

映射使用以下规则匹配 URL:

  • ?匹配一个字符
  • *匹配零个或多个字符
  • **匹配路径中的零个或多个目录
于 2015-09-28T11:18:42.710 回答
0

您是否尝试过使用正则表达式?

就像是:

@RequestMapping("/{value:.}")
于 2015-09-28T11:04:03.803 回答