从数据库获取父级与子级的关系 package com.ninemax.treeNode.view.action;import java.io.IOException;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.apache.struts
package com.ninemax.treeNode.view.action; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.struts2.ServletActionContext; import com.paradise.bean.Condition; import com.paradise.bean.Field; import com.paradise.dao.FieldType; import com.paradise.plus.BaseDaoPlus; public class TreeNodeAction { /** * 根据父类ID获取子类的树菜单 * @throws IOException */ public void findTreeByFid() throws IOException { Condition treeCondition=new Condition(); treeCondition.add(new Field("F_ID",FieldType.STRING)); treeCondition.add(new Field("F_GROUPID",FieldType.STRING)); treeCondition.add(new Field("F_WORD",FieldType.STRING)); String json="["; String sql="SELECT DISTINCT r1.* FROM (SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <= 15000 ) r1," + "(SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <=15000 ) r2" + " WHERE r1.F_ID = r2.F_GROUPID UNION SELECT DISTINCT r4.* FROM (SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <=15000) r3," + "(SELECT * FROM R_WORD_INFO_CHEN WHERE ROWNUM <= 15000) r4 WHERE r3.F_ID = r4.F_GROUPID"; System.out.println(sql); String jsonArr=BaseDaoPlus.find(sql, treeCondition); JSONArray arr=JSONArray.fromObject(jsonArr); for(int i=0;i struts配置文件(需要在主文件中导入struts配置文件)前端实现代码 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>tree view
- 资源分类