@SuppressWarnings("unchecked")
@Override
public JSONArray queryMenu() {
JSONArray array = new JSONArray();
return queryMenuByParent(0,array);
}
/**
* 根据父节点ID获得子节点
* @param parendId
* @return
*/
@SuppressWarnings("unchecked")
public JSONArray queryMenuByParent(int parentId,JSONArray array){
JSONObject obj = new JSONObject();
Query q = factory.getCurrentSession().createSQLQuery("select * from Menu where ParentId="+parentId).setResultTransformer(Transformers.aliasToBean(Menu.class));
List
数据库:
--菜单表(Menu)
create table Menu(
MenuId int primary key identity(1,1) not null,-- 编号
ParentId int default(0) not null,-- 父级菜单编号(0为顶级菜单)
MenuName varchar(50) not null-- 菜单栏名称
)
数据库数据:
[{"id":1,"name":"学员信息管理","node":[]},{"id":2,"name":"基本信息设置","node":[{"id":7,"name":"部门设置","node":[{"id":8,"name":"查询","node":[]},{"id":9,"name":"增加","node":[]},{"id":10,"name":"修改","node":[]},{"id":11,"name":"删除","node":[]}]}]},{"id":3,"name":"资金管理","node":[]},{"id":4,"name":"其他功能","node":[]},{"id":5,"name":"系统管理中心","node":[]},{"id":6,"name":"人力资源","node":[]}]