我们在我们的应用程序中需要一个菜单系统,我们正在使用Spring MVC 3. 菜单将显示在每个页面上,并且菜单项存储在数据库中。处理请求时,将菜单项返回到表示层的想法是什么?在Spring MVC应用程序中创建菜单系统的想法是什么?
非常感谢。
我们在我们的应用程序中需要一个菜单系统,我们正在使用Spring MVC 3. 菜单将显示在每个页面上,并且菜单项存储在数据库中。处理请求时,将菜单项返回到表示层的想法是什么?在Spring MVC应用程序中创建菜单系统的想法是什么?
非常感谢。
您应该使用sitemesh(任何模板引擎可能是tile)与HandlerInterceptorAdapter结合使用。下面是示例代码,
@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).
}
}
并使用请求/会话属性到公共菜单jsp。
你在使用Sitemesh吗?它可以做这样的事情,看看Atlassian的这些幻灯片:http://www.slideshare.net/guest9fefea/sitemesh – nickdos