在Spring MVC应用程序中创建菜单系统的想法是什么? [英] What is the idea for creating a menu system in Spring MVC application?

查看:102
本文介绍了在Spring MVC应用程序中创建菜单系统的想法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序中需要一个菜单​​系统,我们正在使用Spring MVC 3. 菜单将显示在每一页上,并且菜单项存储在数据库中.在处理请求时将菜单项带回到表示层的想法是什么?

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?

非常感谢您.

推荐答案

您应将sitemesh(任何模板引擎可能是图块)与HandlerInterceptorAdapter结合使用.下面是示例代码,

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

并将请求/会话属性用于通用菜单jsp.

and use request/session attribute to common menu jsp.

这篇关于在Spring MVC应用程序中创建菜单系统的想法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆