问题
We need a menu system in our application and we are using Spring MVC 3. The menu will be displayed on every page and and the menu items are stored in the database. What is the idea to bring the menu items back to the presentation layer when handling the requests?
Thank you very much.
回答1:
you should use sitemesh (any templating engine may be tiles) in conjunction with HandlerInterceptorAdapter. Below is sample code,
@Component
public class MenuHandler extends HandlerInterceptorAdapter {
@Autowired
private MenuService menuService;
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
load and set menu items in request attributes (session can also be used).
}
}
and use request/session attribute to common menu jsp.
来源:https://stackoverflow.com/questions/12102153/what-is-the-idea-for-creating-a-menu-system-in-spring-mvc-application