Spring MVC equivalent for Struts 2 Preparable
Is there something similar to Struts 2 Preparable interface / prepare method in Spring 3 MVC?
That is, a method executed every time the controller is requested.
Thanks.
EDIT: What I want to achieve, for example, is to fill a group of properties depending on the user I am, for every request in this cont开发者_如何转开发roller, trying to avoid this:
@Controller
@RequestMapping("my")
public class MyController {
private void fillProperties() {...}
public void request1() {
fillProperties();
...
}
public void request2() {
fillProperties();
...
}
}
You can use Interceptors
Here are a couple of options:
- use a ServletFilter
- add an AOP before advise point cut to match the controller method(s) you want.
- Make a constructor
MyController(){}
- and call all methods
or
- You can also use annotations @postconstruct and @predestroy annotations
https://docs.oracle.com/javaee/5/api/javax/annotation/PostConstruct.html
精彩评论