views:

28

answers:

1

I have some text data from database that I want to display it on all pages on my site. (for example news block etc.) How can I load and pass it to View in Spring Framework 3.0?

I don't want to create some method, which will retrieve data, and call it from each controller...

A: 

Use a HandlerInterceptor, which is built for this purpose - you can specify a piece of logic to execute before or after the execution of your controllers (or a list of controllers - it is up to you to map an interceptor to the controllers it should apply to) by implementing a preHandle() and/or postHandle() method. The latter receives the ModelAndView as an input, allowing you to add model attributes to it.

This way the logic to add some data to the model exists in just one place, can be selectively configured to apply to all or some pages, etc.

matt b