Spring REST 请求映射

Spring REST request mapping

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

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

        }
    }

你试过正则表达式吗?

类似于:

@RequestMapping("/{value:.}")

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

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

In addition to URI templates, the @RequestMapping annotation also supports Ant-style path patterns (for example, /myPath/*.do).

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

The mapping matches URLs using the following rules:

  • ? matches one character
  • * matches zero or more characters
  • ** matches zero or more directories in a path