Service接口:
/**
* @Title: IVoteTreeService.java
* @Package org.Service
* @Description: TODO该方法的主要作用:
* @author A18ccms A18ccms_gmail_com
* @date 2017-5-6 下午10:42:10
* @version V1.0
*/
package org.Service;import java.util.List;import net.sf.json.JSONArray;
import net.sf.json.JSONObject;import org.entity.VoteTree;/** * * 项目名称:testTree * 类名称:IVoteTreeService * 类描述: * 创建人:Mu Xiongxiong * 创建时间:2017-5-6 下午10:42:10 * 修改人:Mu Xiongxiong * 修改时间:2017-5-6 下午10:42:10 * 修改备注: * @version * */
public interface IVoteTreeService {public JSONArray getTreeJson();List<VoteTree> treeList();
}
Service实现类:
/**
* @Title: VoteTreeServiceImpl.java
* @Package org.Service.impl
* @Description: TODO该方法的主要作用:
* @author A18ccms A18ccms_gmail_com
* @date 2017-5-6 下午10:43:10
* @version V1.0
*/
package org.Service.impl;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import net.sf.json.JSONArray;
import net.sf.json.JSONObject;import org.Service.IVoteTreeService;
import org.dao.IVoteTreeDao;
import org.dao.impl.IVoteTreeDaoImpl;
import org.entity.VoteTree;
import org.junit.Test;import com.alibaba.fastjson.JSON;
import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration;/** * * 项目名称:testTree * 类名称:VoteTreeServiceImpl * 类描述: * 创建人:Mu Xiongxiong * 创建时间:2017-5-6 下午10:43:10 * 修改人:Mu Xiongxiong * 修改时间:2017-5-6 下午10:43:10 * 修改备注: * @version * */
public class VoteTreeServiceImpl implements IVoteTreeService {IVoteTreeDao voteTreeDao = new IVoteTreeDaoImpl();public JSONArray getTreeJson(){Map<String, Object> treeMap = new HashMap<String, Object>();Map<String, Object> treejsonMap = new HashMap<String, Object>();treeMap.put("id",1);treeMap.put("text", "用户");treeMap.put("children", treeList());JSONArray jsonObject = JSONArray.fromObject(treeMap);return jsonObject;}@Overridepublic List<VoteTree> treeList() {List<VoteTree> nextSubSet = new ArrayList<VoteTree>();//最小的levelLong minLevel =voteTreeDao.minId(); //一级目录List<VoteTree> friList = voteTreeDao.getFirstLevel(minLevel);for (VoteTree voteTree : friList) {//根据一级目录查找所有的子集voteTree.setChildren(nextSubSet);nextSubSet =voteTreeDao.getNextSubSet(voteTree);}return nextSubSet;}}