tree数据格式封装处理

1,先创建关于tree的属性bean
public class TreeNode {

	private String id;
	
	private String text;
	
	private String url;
	
	private String state;//value closed,open
	
	private boolean checked; //
	
	private String parentId;
	
	private String iconCls; //图标
	
	private Map attributes = new HashMap();
	
	private List  children;
	

	public String getId() { 
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public  String getParentId() {
		return parentId;
	}

	public void setParentId( String parentId) {
		this.parentId = parentId;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public List getChildren() {
		return children;
	}

	public void setChildren(List children) {
		this.children = children;
	}

	public Map getAttributes() {
		return attributes;
	}

	public void setAttributes(Map attributes) {
		this.attributes = attributes;
	}

	/**
	 * @return the iconCls
	 */
	public String getIconCls() {
		return iconCls;
	}

	/**
	 * @param iconCls the iconCls to set
	 */
	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}
	
}
2,然后创建一个tree的工具类
public class TreeUtil {

	/**
	 * 菜单封装tree格式
	 * @param sysMenus
	 * @param string
	 * @return
	 */
	public static List MenuToNode(List sysMenus,String string) { //先封装父节点
		List newTrees = new ArrayList();
		TreeNode tn = null;
		if(sysMenus.size()!=0){
			for(int i = 0;i

你可能感兴趣的:(java代码)