已经搜索过论坛,没有找到答案,谢谢!

解决方案 »

  1.   

    可以参考:http://download.csdn.net/download/luck332/995421
      

  2.   

    我是放到 MAP LIST 里面通过GSON生成
      

  3.   

    Category.java-获取数据源并构造为树的算法:
    package com.biristone.service.tree;import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import com.biristone.service.ProTypeService;
    import com.biristone.pojo.ProType;public class Category {
    private static String configFile = "applicationContext-services.xml";
    private static ApplicationContext context = new ClassPathXmlApplicationContext(configFile);
        private static Map<Long, Category> catMap = new HashMap<Long, Category>();
    private static ProTypeService ps = (ProTypeService)context.getBean("proTypeService");
    private static List<ProType> ptp;
        
    static 
    {
    BuildAllCategory(-1);
    }
        //根据产品分类构造树
        public static void BuildAllCategory(int id)
        {
            ptp = ps.getTypeByPid(id);
            List<Category> childs = new ArrayList<Category>(); 
            //如果没有父节点,则为根节点
        if(id==-1)
        {
        new Category(0,ptp.get(0).getName());
        BuildAllCategory(ptp.get(0).getTid());
        }
        else
        {
        for(ProType node:ptp)
        {
        childs.add(new Category((long)node.getTid(),node.getName()));
        }
        //挂到相应的父节点
        Category.getById((long)id).setChildren(childs);
       
        //如果子节点还有子节点
        for(Category child:childs)
        {
        if(null!=ps.getTypeByPid((int)child.getId()))
        {
        BuildAllCategory((int)child.getId());
        }
        }
        }  
        }
        
        public static Category getById(long id) {
            return catMap.get(id);
        }    private Long id;
        private String name;
        private List<Category> children;
        private boolean toggle;    public Category(long id, String name, Category... children) {
            this.id = id;
            this.name = name;
            this.children = new ArrayList<Category>();
            for (Category child : children) {
                this.children.add(child);
            }        catMap.put(id, this);
        }    public long getId() {
            return id;
        }    public void setId(long id) {
            this.id = id;
        }    public String getName() {
            return name;
        }    public void setName(String name) {
            this.name = name;
        }    public List<Category> getChildren() {
            return children;
        }    public void setChildren(List<Category> children) {
            this.children = children;
        }    public void toggle() {
            toggle = !toggle;
        }    public boolean isToggle() {
            return toggle;
        }
    }tp_type表:tid为分类,pid为上级分类,name为分类名
    Category.getById(根节点编号)就返回整个分类树了关键部分都列出来了,里面的表结构映射的bean和action、Category转成json就不用我多说了吧。
      

  4.   

    我记得easyui 里面好像有这样的例子