Imagine we have a controller like this:
@RestController
@RequestMapping("/{parameter}")
public class MyController {
@ExceptionHandler(SomeException.class)
public Object handleSomeException() { /* handle */ }
@RequestMapping("/something")
public Object handleSomething(@PathVariable("parameter") String parameter) {
/* handle */
}
@RequestMapping("/somethingElse")
public Object handleSomethingElse(@PathVariable("parameter") String parameter) {
/* handle */
}
}
The question is, how to implement some common pre-\post-handling for this particular controller in similar way as @ExceptionHandler
is working? E.g. I want to have a method in controller which receives request prior to handler methods, but only requests for this particular controller.
I'm aware of RequestBodyAdvice
and ResponseBodyAdvice
interfaces, but want something local to controller.
As a usage example - I want to do some validation for common parameter
variable before each handler.