java 组装树形结构

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

package cn.thinkjoy.kidscare.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.util.CollectionUtils;

import java.util.*;


/***
 *
 * @ClassName: TreeUtils
 * @Description: 组织树结构
 * @author liyuhang
 *
 */
public class TreeUtils {

	/****
	 *
	 * @Title: getTreeByStack
	 * @Description: 获取树形结构字符串
	 * @param  jsonRootList 所有根结点
	 * @return String  树形字符串
	 */
	public static String getTreeByStack(JSONArray jsonRootList, Map parentMap){
		Stack stack=new Stack();
		for(int i=0;i nodeAll, List selectedIds, SerializeFilter[] filters){

		if (ArrayUtils.isEmpty(filters)) {
			SimplePropertyPreFilter simplePropertyPreFilter = new SimplePropertyPreFilter();
			filters = new SerializeFilter[]{simplePropertyPreFilter};
		}

		Map parentMap = new HashMap<>();
		JSONArray rootList = new JSONArray();
        if (!CollectionUtils.isEmpty(nodeAll)) {
            JSONArray jsonListAll = JSONArray.parseArray(JSON.toJSONString(nodeAll,filters));
            for(int i=0;i

转载于:https://my.oschina.net/u/3238650/blog/3003476

你可能感兴趣的:(java 组装树形结构)