zTree的联想[将数据表封装成自定义TreeNode,再将TreeNode生成json字串

由zTree的示范我们看到zTree支持多种数据类型,我认为json是最好的,项目中json肯定来自数据库,不可能就这样纯粹静态的,如何将数据库表中的属性信息生成json呢,这是关键问题,比如数据表读出的数据可能如下:

//用一个集合模拟数据表的内容,也就是一下集合的内容完全可以查询自数据库
		List<SysFunction> treeList = new ArrayList<SysFunction>();
		treeList.add(new SysFunction("L01", null, "营销管理"));		
		treeList.add(new SysFunction("L02",null,"客户管理"));
		treeList.add(new SysFunction("L03",null,"服务管理"));		
		//营销管理的子功能
		treeList.add(new SysFunction("L0101","L01","创建销售机会"));
		treeList.add(new SysFunction("L0102","L01","指派销售机会"));
		treeList.add(new SysFunction("L0103","L01","制定开发计划"));
		treeList.add(new SysFunction("L0104","L01","执行开发计划"));
		//指派销售机会的子功能		
		treeList.add(new SysFunction("L010201","L0102","经理指派"));
		treeList.add(new SysFunction("L010202","L0102","主管指派"));				
		//客户管理的子功能
		treeList.add(new SysFunction("L0201","L02","客户信息管理"));
		treeList.add(new SysFunction("L0202","L02","客户流失管理"));
		//服务管理子功能
		treeList.add(new SysFunction("L0301","L03","咨询服务管理"));
		treeList.add(new SysFunction("L0302","L03","投诉服务管理"));
		treeList.add(new SysFunction("L0303","L03","查询服务管理"));




这里的SysFunction类封装的是系统功能表,这个类的定义如下:

/**
 * 系统功能对象
 * */
class SysFunction {
	
	private String code;
	private String parentCode;
	private String title;

	/**功能编号*/
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	/**父级功能编号*/
	public String getParentCode() {
		return parentCode;
	}

	public void setParentCode(String parentCode) {
		this.parentCode = parentCode;
	}
	/**功能名称,现在树上的节点文本*/
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public SysFunction(String code, String parentCode, String title) {
		super();
		this.code = code;
		this.parentCode = parentCode;
		this.title = title;
	}

	public SysFunction() {
		super();
	}
}


每个功能可能有一个父功

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值