I have a number of controller methods spread over a number of classes. Every method takes a Model object and all of my methods populate some shared properties into the model (control the navigation bar display mostly). Is there a way for me to plug a ‘base’ method into Spring? I want one method that can populate my shared properties and then go into the specific controller method (or reversed for that matter). Does anybody know how to do that?
I have a number of controller methods spread over a number of classes. Every
Share
Sounds like a HandlerInterceptor might be a good approach.
It’s a bit AOP like — you can define a class that has a
PreHandleorPostHandlemethod, and configure which requests it will run on. In your case you probably want aPostHandle, since that will give you access to the ModelAndView, so you can populate it with the shared items.