Anand Sai Krishna
Anand Sai Krishna

Reputation: 319

Spring REST request mapping

I want to configure Spring to redirect all the requests to a specific Controller irrespective of the URL (length and parameters). How should I give the URL pattern / regular expression in the RequestMapping annotation. I tried using the below code, but it is not working. Any help in this regard is deeply appreciated.

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

        }
    }

Upvotes: 1

Views: 2469

Answers (2)

sp00m
sp00m

Reputation: 48807

You need @RequestMapping(method = RequestMethod.GET, value = "/**").

From 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).

From 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

Upvotes: 7

Gianluca Tomasino
Gianluca Tomasino

Reputation: 36

Have you tried with a regular expression?

Something like:

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

Upvotes: 0

Related Questions