基于SSM的组织树的实现
来源:互联网 发布:bs点炒股软件 编辑:程序博客网 时间:2024/06/05 15:53
基于SpringMvc的组织树的实现
Controller 层代码
import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import com.chengpai.person.bean.bumenMidObject;import com.chengpai.person.service.bumenService;import util.tree.Node;@Controllerpublic class bumenController {@Autowiredprivate bumenService bs;@RequestMapping(value = "/bumen/testdata1.do")@ResponseBodypublic String testdata1(HttpServletRequest request, HttpServletResponse response) {List dataList = bs.selectAll();//dataList.clear();// 节点列表(散列表,用于临时存储节点对象)HashMap nodeList = new HashMap();// 根节点Node root = null;// 根据结果集构造节点列表(存入散列表)for (Iterator it = dataList.iterator(); it.hasNext();) {Map dataRecord = (Map) it.next();Node node = new Node();node.id = (String) dataRecord.get("id");node.text = (String) dataRecord.get("text");node.parentId = (String) dataRecord.get("parentId");nodeList.put(node.id, node);}// 构造无序的多叉树Set entrySet = nodeList.entrySet();for (Iterator it = entrySet.iterator(); it.hasNext();) {Node node = (Node) ((Map.Entry) it.next()).getValue();if (node.parentId == null || node.parentId.equals("")) {root = node;} else {((Node) nodeList.get(node.parentId)).addChild(node);}}// root.sortChildren();System.out.println("["+root.toString()+"]");return "["+root.toString()+"]";}}Service层代码:
import java.util.List;import com.chengpai.person.bean.bumenMidObject;import com.chengpai.person.bean.bumen;public interface bumenService { List<bumen> selectAll(); List<Integer> listRoot(); List<Integer> listRooti(int i); List<bumenMidObject> Findnodes(int i);}
ServiceImp层代码:
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.chengpai.person.bean.bumenMidObject;import com.chengpai.person.bean.bumen;import com.chengpai.person.mapper.bumenMapper;import com.chengpai.person.service.bumenService;@Service("bumenService")public class bumenServiceImp implements bumenService {@Autowiredprivate bumenMapper bm;@Overridepublic List selectAll() {// TODO Auto-generated method stubList<bumen> listbumen= bm.selectAll();List dataList = new ArrayList();for (int i = 0; i < listbumen.size(); i++) { HashMap dataRecord = new HashMap(); if(listbumen.get(i).getFid()==0){ dataRecord.put("id", listbumen.get(i).getId()+""); dataRecord.put("text", listbumen.get(i).getName()); dataRecord.put("parentId", null); dataList.add(dataRecord); }else{ dataRecord.put("id", listbumen.get(i).getId()+""); dataRecord.put("text", listbumen.get(i).getName()); dataRecord.put("parentId", listbumen.get(i).getFid()+""); dataList.add(dataRecord); }}return dataList;}@Overridepublic List<Integer> listRoot() {// TODO Auto-generated method stubList<Integer> listRoot= new ArrayList<Integer>();List<bumen> listbumen= bm.selectAll();for (int i = 0; i < listbumen.size(); i++) {if(!listRoot.contains(listbumen.get(i).getFid())){listRoot.add(listbumen.get(i).getFid());}}return listRoot;}@Overridepublic List<Integer> listRooti(int i) {// TODO Auto-generated method stubreturn null;}@Overridepublic List<bumenMidObject> Findnodes(int i) {// TODO Auto-generated method stubreturn null;}}
Mapper 层代码实现
import java.util.List;import org.apache.ibatis.annotations.Select;import com.chengpai.person.bean.bumen;public interface bumenMapper {@Select("select * from bumen") List<bumen> selectAll();}部门实体类:
public class bumen {private int id;private String name;private int fid;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getFid() {return fid;}public void setFid(int fid) {this.fid = fid;}}
阅读全文
0 0
- 基于SSM的组织树的实现
- 基于d3.js的组织结构图实现
- 基于SSM和jstl的分页实现
- 基于SSM的博客网的设计与实现
- 2017/2/24 基于SSM的RESTful实现
- 基于SSM框架实现数据库的基本功能(一)
- 基于SSM框架学生管理系统的实现
- 基于SSM的word处理
- 基于SSM整合的分页
- 基于ssm的上传图片
- 基于SSM的项目搭建
- 基于SSM框架的分页
- django 实现的组织架构树
- 基于SSM实现的简易员工管理系统(基于阿里云的网站上线篇)
- 基于SSM实现的简易员工管理系统(基于阿里云的网站上线篇)
- 基于SSM实现的简易员工管理系统(基于阿里云的网站上线篇)
- 自组织神经网络的实现
- 基于网格的空间数据组织
- 双向链表的操作
- springboot实现ajax跨域请求
- (十二)定时事件集成到多路IO机制
- windows+tensorflow+fasterRcnn---3
- 3. Longest Substring Without Repeating Characters
- 基于SSM的组织树的实现
- 虚拟机可正常启动但虚拟机窗口无法正常显示
- 我的第一篇博客
- 百度语音合成的使用
- eclipse导入一个项目之后没有JRE System Library怎么办?
- Linux功耗管理(30)Linux CPU core的电源管理(2)_cpu topology
- java中substring与substr的用法
- expect 安装
- java 征程第一步,从环境开始。