1. 程式人生 > >無限級聯動遞迴查詢上級節點

無限級聯動遞迴查詢上級節點

最近專案中遇到的問題做下總結

遞迴查詢 : (無限級聯)樹的最末尾端的code反查上級所有節點 ##

public List<Map<String, Object>> getCategoryByImtemcode(String itemcode) throws Exception {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        getCategList(itemcode, list);
        return
list; } //私有方法 private List<Map<String, Object>> getCategList(String itemCode, List<Map<String, Object>> cateList) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); JrcommCategroyDict jc = jrcommCategroyDictDao.
selectCategoryDictByImtemcode(itemCode); //根節點返回遞迴結束 if (!jc.getItemCode().equals("00")) { map.put("itemName", jc.getItemName()); map.put("itemCode", jc.getItemCode()); map.put("level", jc.getLevel()); map.put("dimension", jc.getDimension()); cateList.
add(map); return getCategList(jc.getPcode(), cateList); } return cateList; }