纯Struts2 AJAX树实现方式及源码(三)

2014-11-24 02:31:19 · 作者: · 浏览: 6
e new name */ public void setName(String name) { this.name = name; } /** * Gets the children. * * @return the children */ public List getChildren() { return children; } /** * Sets the children. * * @param children the new children */ public void setChildren(List children) { this.children = children; } }

TREE对象类: CategoryImpl.java

package com.jdframe.sys.biz.org;

import java.util.*;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import com.jdframe.sys.core.model.tree.Category;
import com.jdframe.sys.core.util.DbUtils;
import com.jdframe.sys.dao.model.T_sys_organization;

// TODO: Auto-generated Javadoc
/**
 * The Path : com.jdframe.sys.biz.org.CategoryImpl.java
 * The   CategoryImpl
 * Last-Modified-Time : 2014-2-20 21:33:19
 * @author support@jdframe.com
 * @version  2.0.3.0
 *  http://www.jdframe.com
 * @see 
 */
public class CategoryImpl extends Category {
	
	/** The log. */
	Logger log = Logger.getLogger(CategoryImpl.class);
	
	/**
	 * Instantiates a new category impl.
	 */
	public CategoryImpl(){
		
	}
	
	/**
	 * Instantiates a new category impl.
	 *
	 * @param id the id
	 * @param name the name
	 * @param children the children
	 */
	public CategoryImpl(String id, String name, CategoryImpl... children) {
		//super(id, name, children);
		this.id = id;
		this.name = name;
		this.children = new ArrayList
  
   ();
		for (CategoryImpl child : children) {
			this.children.add(child);
		}
		// TODO Auto-generated constructor stub
	}
	
	/* (non-Javadoc)
	 * @see com.jdframe.sys.core.model.tree.Category#getById(java.lang.String)
	 */
	@Override
	public  CategoryImpl getById(String sj_dm){
		
		SqlSession session = DbUtils.buildSqlSession();
		CategoryImpl root_cat  = null;
		try{
			 
			List
   
     all = session.selectList("getSubOrgByDm",sj_dm); List allCategory = new ArrayList(); for (int j = 0; j < all.size(); j++) { CategoryImpl self_category = null; String self_code = all.get(j).getZzjg_dm(); String self_name = all.get(j).getZzjg_name(); List
    
      l = session.selectList("getSubOrgByDm",self_code); List subCategory = new ArrayList(); for (int i = 0; i < l.size(); i++) { String _code = l.get(i).getZzjg_dm(); String _name = l.get(i).getZzjg_name(); subCategory.add(new CategoryImpl(_code,_name)); } if(subCategory.size()>0){ CategoryImpl[] childr = new CategoryImpl[subCategory.size()]; for (int i = 0; i < subCategory.size(); i++) { if(subCategory.get(i) instanceof CategoryImpl){ childr[i] = (CategoryImpl)subCategory.get(i); } } self_category = new CategoryImpl(self_code,self_name,childr); }else{ self_category = new CategoryImpl(self_code,self_name); } allCategory.add(self_category); } CategoryImpl[] allchildr = new CategoryImpl[allCategory.size()]; if(allCategory.size()>0){ for (int i = 0; i < allCategory.size(); i++) { if(allCategory.get(i) instanceof CategoryImpl){ allchildr[i] = (CategoryImpl)allCategory.get(i); } } root_cat = new CategoryImpl("-1","Root",allchildr); }else{ root_cat = new CategoryImpl("-1","Root"); } //if(sj_dm.equals("76300000000")){ // root_cat = self_category; //} }finally{ if(session!=null)session.close(); } return root_cat; } /* (non-Javadoc) * @see com.jdframe.sys.core.model.tree.Category#getRootById(java.lang.String) */ @Override public CategoryImpl getRootById(String id) { // TODO Auto-generated method stub SqlSession session = DbUtils.buildSqlSession(); CategoryImpl root_cat = null; try{ List
     
       all = session.selectList("getOrgBySwjgDm",id); List allCategory = new ArrayList(); for (int j = 0; j < all.size(); j++) { CategoryImpl self_category = null; String self_code = all.get(j).getZzjg_dm(); String self_name = all.get(j).getZzjg_name(); List
      
        l = session.selectList("getSubOrgByDm",self_code); List subCategory = new ArrayList(); for (int i = 0; i < l.size(); i++) { String _code = l.get(i).getZzjg_dm(); String _name = l.get(i).getZzjg_name(); subCategory.add(new CategoryImpl(_code,_name)); } if(subCategory.size()>0){ CategoryImpl[] childr = new CategoryImpl[subCategory.size()]; for (int i = 0; i < subCategory.size(); i++) { if(subCategory.get(i) instanceof CategoryImpl){ childr[i] = (CategoryImpl)subCategory.get(i); } } self_category = new CategoryImpl(self_code,self_name,childr); }else{ self_category = new CategoryImpl(self_code,self_name); } allCategory.add(self_category); } CategoryImpl[] allchildr = new CategoryImpl[allCategory.size()]; if(allCategory.size()>0){ for (int i = 0; i < allCategory.size(); i++) { if(allCategory.get(i) instanceof CategoryImpl){ allchildr[i] = (CategoryImpl)allCategory.get(i); } } root_cat = new CategoryImpl("-1","Root",allchildr); }else{ root_cat = new CategoryImpl("-1","Root"); } }finally{ if(session!=null)session.close(); } return root_cat; } } 
      
     
    
   
  


应用效果:

\\