开发者

How to display the same data on all pages in Spring Framework 3.0?

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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜