What is the idea for creating a menu system in Spring MVC application?

六眼飞鱼酱① 提交于 2019-12-13 04:25:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!