對於 樹形 數據的遞歸java
1. 在model中添加 屬性 須要添加 Department 屬性,List<Department>this
public class Department { private String NAME; //名稱 private String NAME_EN; //英文名稱 private String BIANMA; //編碼 private String PARENT_ID; //上級ID private String HEADMAN; //負責人 private String TEL; //電話 private String FUNCTIONS; //部門職能 private String BZ; //備註 private String ADDRESS; //地址 private String DEPARTMENT_ID; //主鍵 private String target; private Department department; private List<Department> subDepartment; private boolean hasDepartment = false; private String treeurl; private String icon; }
2. 編碼
/** * 獲取全部數據並填充每條數據的子級列表(遞歸處理) * @param MENU_ID * @return * @throws Exception */ public List<Department> listAllDepartment(String parentId) throws Exception { List<Department> departmentList = this.listSubDepartmentByParentId(parentId); for(Department depar : departmentList){ //設置頁面顯示屬性 depar.setTreeurl("department/list.do?DEPARTMENT_ID="+depar.getDEPARTMENT_ID()); //設置子屬性 depar.setSubDepartment(this.listAllDepartment(depar.getDEPARTMENT_ID())); depar.setTarget("treeFrame"); depar.setIcon("static/images/user.gif"); } return departmentList; }