1
我想問如何使用遞歸函數從數據庫生成menumodel。 我已經讓這個班,但它不工作。請幫幫我,我已經找到並嘗試了一個星期.thanks從數據庫生成Primefaces MenuModel
public class MenuDAOImpl extends ManagerBase<MenuMaster> implements MenuDAO {
private List<MenuMaster> list;
private List<MenuData> datas;
@Override
public MenuModel getMenu() {
MenuModel model = new DefaultMenuModel();
String[] orders = new String[]{"id"};
try {
list = getBySQLQuery("PARENT_MENU_ID=0", orders, 1000);
for (MenuMaster menuMaster : list) {
menuChild(menuMaster);
}
} catch (Exception e) {
}
return model;
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private List<MenuData> menuChild(MenuMaster master) {
List<MenuData> listChild = new ArrayList<MenuData>();
String[] orders = new String[]{"id"};
try {
MenuData data = new MenuData();
data.mm = master;
data.mms = getBySQLQuery("PARENT_MENU_ID=" + master.getParentMenuId(), orders, 1000);
listChild.add(data);
} catch (Exception e) {
}
return listChild;
}
public class MenuData {
private MenuMaster mm;
private List<MenuMaster> mms;
public MenuData() {
}
public MenuMaster getMm() {
return mm;
}
public void setMm(MenuMaster mm) {
this.mm = mm;
}
public List<MenuMaster> getMms() {
return mms;
}
public void setMms(List<MenuMaster> mms) {
this.mms = mms;
}
}
}
這是我的數據庫表(抱歉,我不能上傳圖片)
ID | MENU_NAME | DISPLAY_NAME |網址| PARENT_MENU_ID |
1 |員工|員工| /employee.xhtml | 0 |
2 | employeemenu |員工| /employee.xhtml | 1 |
3 | utils |實用程序| | 0 |
7 | asdf | asdf | | 6 |
6 | utilsmenu |測試| | 3 |
5 | utilsdata |管理員配置| asdf | 3 |
4 |菜單|菜單編輯器| /utility/menu.xhtml | 3 |
你能告訴我SpFeModuleForUser類?我是痘痘混淆,有多少菜單級別我可以生成?謝謝 – satoo 2013-04-24 23:43:30
以及這只是我的模型類,我有兩個級別,SubMenu和MenuItems – RuntimeError 2013-04-25 02:47:50