XZen
XZen

Reputation: 445

Request mapping in Spring, regexp as parameter in annotation

I have such code:

@RequestMapping("/apple")
public void handleApple(HttpServletRequest request, HttpServletResponse response) throws IOException {
     <...>
}

@RequestMapping("/test/apple")
public void handleTestApple(HttpServletRequest request, HttpServletResponse response) throws IOException {
     <...>
}

Is it possible to combine these two methods in one, but not like:

@RequestMapping("/**/apple")
public void handleApple(HttpServletRequest request, HttpServletResponse response) throws IOException {
    <...>
}

Since it will allow another URLs besides started with 'test' which is not applicable in my case.

Upvotes: 0

Views: 71

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279930

If it's just those two paths and you'd want them handled with a single handler method, simply choose one of your methods and annotate it with

@RequestMapping(value = {"/apple", "/test/apple"})

Upvotes: 1

Related Questions