开发者

Spring MVC and Template Variables

Using Spring MVC 3.0 with sitemesh and freemarker.

I'm trying to get the username of the currently logged in user to display at the top of the sitemesh decorator.

The question, then, is how do I expose this variable to all (or a subset of) my controllers?

I could add it to all of my models manually, but this seems impractical:

ModelAndView mav = new ModelAndView("test");
mav.addObject("user", userName);
return mav;

Especially if I want to 开发者_开发百科make more of the template dynamic.

In struts, this was done by extending all actions from a base action, and adding a getUser method to the base, but I can't figure out how to do this in spring.

Any ideas?

Thanks! Tim


See http://blog.humandoing.net/2006/03/06/interceptors-in-spring/ for an example of how this can be done using a Spring interceptor

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜