java - Spring MVC: Insert values into all my ModelAndView s -
I have a mid-sized spring application and I add key / value pairs to all the models and scenes in cross cutting fashion I want to include (like AOP).
Inspiration is to add all the pages (configuration values, build numbers, etc.).
What is the easiest way to do this? I prefer without AOP but I am ready to use it if necessary.
You have several options here. /
- Write a custom
handler interceptor
, and override theposthand ()
method, supply your data toModelAndView
. - If your data is static, you can use it in
ViewResolver
inattributes
toUrlBasedViewResolver . This is useful only for real string-based configs that you can put in your beans file.
- With a
@ModelAttribute
a method has been commented in your controller. Any object returned from such annotated methods is automatically added to the model. This will be done only for those requests managed by the@Requestmapping
-annotated methods in that controller class. - With a
Comments
Post a Comment