My use struts menu dynamic from the database built tree menu design

xiaoxiao2021-03-06  40

About Struts-Menu, there is only two articles of the Blue Sky Website Webmaster to spread, thank you here.

1. "Source Analysis" see http://champion.ewuxi.com/old/opensource/struts-new/strutsmenu.htm

2. "Ibatis small code dynamic build tree" See http://www.ewuxi.cn/ithomeData/200406/489.html

In our project, several tree menus are used, such as organizational institutions and departments, system modules, which are based on a single table, I spent a morning, I think about a design, very immature, I hope everyone tells me where I don't Hit, I change.

Use struts-menu2.3 and iBATIS2.0, in addition, I also used Spring, class diagrams are as follows:

Design Idea: Meunrule is obviously a strategy mode. When constructing a tree based on a single table, in order to satisfy the opening and closing principle, the variable part has two, one is the corresponding SQLMAP name, and the rules attached to another node (including URL ACTION TARGET, etc.), rules are generally determined by their own information, naturally, menule, including these two parts, of course, if you have recorded these fields in detail, there is no need to work again. These are not included in our table design.

The Menutree class requires the Spring container to inject two properties. First, Menudao, the other is Menule. Too manu, a type of menu corresponds to a menuTree instance, the main methods in this class are as follows:

public MenuRepository getMenuRepository (Object paramObject) {MenuRepository repository = new MenuRepository (); List items = menuDao.getMenuItemList (menuRule.getSqlMapId (), paramObject); MenuItem item; for (int i = 0; i

Menuitem This class is a packager for MenuComponent, in order to handle the father and child relationship.

Finally, the step of the client call:

1. Create a specific menule subclass, one type of tree menu; 2. Assess each type of TreeUn object in the root configuration file, inject the menuDao property and the menule property; 3. Use the system's serviceLocate or context Bean plant Class to generate TreeMenu instances such as gettreeMenu (String MenulogicName). 4. Call TreeMenu.getMenurePository (Object Param) to construct the tree 5. In the Struts action, set to the Menudisplayer property, and finally place the context environment for JSP page display. (Note: This feeling is more than the case.) Because Ibatis cache is used, the performance of reading this part from the database is improved, and the number of nodes is not large, and the pressure is not large, and the one-time read program will be taken first. .

转载请注明原文地址:https://www.9cbs.com/read-70873.html

New Post(0)