利用VIS插件调用后台数据库显示动态流程图


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

 
   ZTREE DEMO 
  

    
    


  



 










getNodes内容


	@RequestMapping(value="/getNodes", method=RequestMethod.POST)
	public void getNodes(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		//nodes 获取节点列表
		List queryResult=flowService.getAll();
		List lstTree = new ArrayList(); 
		
		for(Flow flow:queryResult)
		{
			//name != null && !name.equals("")
			if( (null!=flow.getImagepath())&&(!"".equals(flow.getImagepath())) )
			{
				lstTree.add( ("{id:"+flow.getFid()+",label:'"+flow.getLabel()+"',level:"+flow.getLevelid()+","+
						 "image:'<%=request.getContextPath()%>"+flow.getImagepath().toString()+"',shape:'image'"+
						 "}").replace("\"","")  );//生成符合格式的内容
			}
			else
			{
				
				lstTree.add( ("{id:"+flow.getFid()+",label:'"+flow.getLabel()+"',level:"+""+flow.getLevelid()+
						 "}").replace("\"","") );
			}
			

			
		}
		
		
		//edges
		List lstTree2 = new ArrayList(); 
		
		for(Flow flow:queryResult)//生成符合格式的内容
		{
			StringBuilder stringFlow = new StringBuilder("");//组合
			if( (null!=flow.getNextid()) &&(!"".equals( String.valueOf(flow.getNextid()) )) )//下一个节点不为空
			{
				System.out.println(" nextIdString is "+String.valueOf(flow.getNextid()) );
				
				if( (null!=flow.getLength()) &&(!"".equals( String.valueOf(flow.getLength()) )) )//线段的长度不为空
				{
					
					stringFlow=new StringBuilder( (stringFlow.toString()+"{from:"+flow.getFid()+",to:"+flow.getNextid()+",label:'"+flow.getEdgeslabel()+"',length:"+flow.getLength()+"}").replace("\"","") );
				}
				else
				{
					
					stringFlow=new StringBuilder( (stringFlow.toString()+"{from:"+flow.getFid()+",to:"+flow.getNextid()+",label:'"+flow.getEdgeslabel()+"'"+"}").replace("\"","") );
				}
			}
			else
			{
				break;
				
				
			
			}
			System.out.println( stringFlow.toString() );
			lstTree2.add(stringFlow.toString());
			
		}
		
		List allList=new ArrayList();

		

		response.getWriter().print(  JSONArray.fromObject("[{\"nodes\":\""+lstTree+"\",\"edges\":\""+lstTree2 +"\"}]").toString()  );//打包成JSON对象
	}



你可能感兴趣的:(jquery)