2019独角兽企业重金招聘Python工程师标准>>>

1.第一步配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns=" http://java.sun.com/xml/ns/javaee"
 xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <!-- 配置spring的监听器 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext*.xml</param-value>
    </context-param>
    <!-- 开启监听 -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <!-- 配置OpenSessionInViewFilter,必须在struts2监听之前 -->
    <filter>
        <filter-name>sessionFilter</filter-name>
        <filter-class>
            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        </filter-class>
    </filter>
    <filter-mapping>
     <filter-name>sessionFilter</filter-name>
     <url-pattern>*.action</url-pattern>
    </filter-mapping>
     <!-- 配置OpenSessionInViewFilter结束-->
    
  <!-- 配置权限过滤器 --> 
   <filter>
     <filter-name>authFilter</filter-name>
     <filter-class>com.litsoft.cctv.twxt.common.auth.AuthFilter</filter-class>
   </filter> 
   <filter-mapping>
     <filter-name>authFilter</filter-name>
     <url-pattern>/</url-pattern>
   </filter-mapping>
   <!-- 配置权限过滤器结束 --> 
  
   <!-- 配置struts2 -->
   <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
   </filter>
   <!-- sturts2*.jsp配置拦截 -->
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.jsp</url-pattern>
  </filter-mapping>
  <!--struts2 *.action配置拦截 --> 
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.action</url-pattern>
  </filter-mapping>
  <!--配置struts2结束 -->
  
   <!-- 欢迎页面 -->
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
</web-app>

2.第二步加载spring,struts,hibernate配置文件

spring配置文件如下

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <!-- 配置事务管理器 -->
 <bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
 </bean>
 
 <!-- 配置hibernate适配器 -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
     <prop key="hibernate.show_sql">true</prop>
     <prop key="hibernate.hbm2ddl.auto">update</prop>
   </props>
  </property>
  <property name="mappingResources">
   <list>
    <value>com/litsoft/cctv/twxt/common/po/OaUser.hbm.xml</value>
    <value>com/litsoft/cctv/twxt/common/po/OaRole.hbm.xml</value> 
    <value>com/litsoft/cctv/twxt/common/po/OaDept.hbm.xml</value>
   </list>
  </property>
 </bean>

<!-- 配置声明式事务 拦截器 -->
 <bean id="transactionInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager" ref="transactionManager"></property>
  <property name="transactionAttributes">
   <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
    <prop key="add*">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>

<!--aop 管理*.service管理 -->
 <bean
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="proxyTargetClass" value="true"></property>
  <property name="beanNames">
   <value>*Service</value>
  </property>
  <property name="interceptorNames">
   <list>
    <value>transactionInterceptor</value>
   </list>
  </property>
 </bean>

<!-- 配置baseDao -->
 <bean id="baseDao" class="com.litsoft.cctv.twxt.common.dao.impl.BaseDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>

<!-- 配置baseService -->
 <bean id="baseService" class="com.litsoft.cctv.twxt.common.service.impl.BaseServiceImpl">
  <property name="baseDao" ref="baseDao"></property>
 </bean>
 
 <bean id="leagueMemberService" class="com.litsoft.cctv.twxt.leaguemembermanage.service.impl.LeagueMemberServerImpl">
  <property name="baseDao" ref="baseDao"></property>
 </bean>
 
 <!-- 配置用户管理action -->
 <bean name="leaguemembermanage_UserManagerAction" class="com.litsoft.cctv.twxt.leaguemembermanage.ui.action.UserManagerAction" scope="prototype">
        <property name="baseService">
           <ref bean="baseService"/>
        </property>
 </bean>
 
  <!-- 配置用户管理action -->
 <bean name="leaguemembermanage_LeagueMemberAction" class="com.litsoft.cctv.twxt.leaguemembermanage.ui.action.LeagueMemberAction" scope="prototype">
        <property name="leagueMemberService">
           <ref bean="baseService"/>
        </property>
 </bean>

</beans>

数据源

applicationContext-dataSource.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!-- 配置数据源 -->
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName">
   <value>com.mysql.jdbc.Driver</value>
  </property>
  <property name="username">
   <value>root</value>
  </property>
  <property name="password">
   <value>root</value>
  </property>
  <property name="url">
   <value>jdbc:mysql://localhost:3306/OA_XZXT?useUnicode=true&amp;continueBatchOnError=true&amp;characterEncoding=utf-8</value>
  </property>
  <property name="removeAbandoned">
   <value>true</value>
  </property>
  <property name="defaultAutoCommit">
   <value>true</value>
  </property>
  <property name="removeAbandonedTimeout">
   <value>60</value>
  </property>
  <property name="validationQuery">
   <value>SELECT 1</value>
  </property>
  <property name="logAbandoned">
   <value>true</value>
  </property>
  <property name="testWhileIdle">
   <value>true</value>
  </property>
  <property name="timeBetweenEvictionRunsMillis">
   <value>10000</value>
  </property>
  <property name="minEvictableIdleTimeMillis">
   <value>6000</value>
  </property>
  <property name="testOnBorrow">
   <value>true</value>
  </property>
  <property name="maxActive">
   <value>150</value>
  </property>
  <property name="maxIdle">
   <value>30</value>
  </property>
  <property name="minIdle">
   <value>10</value>
  </property>
  <property name="initialSize">
   <value>10</value>
  </property>
 </bean>
</beans>

spring配置文件结束

struts2配置文件

采用通配符形式

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
   <constant name="struts.objectFactory" value="spring" />
   <include file="struts-cctvbase.xml"/>
 <!-- Add packages here -->
 <package name="actions" namespace="/" extends="cctv-base">
  <action name="*_*_*" class="com.litsoft.cctv.twxt.{1}.ui.action.{2}" method="{3}">
   <result name="input">${input_url}</result>
   <result name="forward_url">${forward_url}</result>
   <result name="redirect_url" type="redirect">${redirect_url}</result>
  </action>
  
 </package>

</struts>

struts-cctvbase.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
 <!-- Add packages here -->
 <package name="cctv-base" namespace="/" extends="struts-default">
  <interceptors>
   <interceptor name="catchException"
    class="com.litsoft.cctv.twxt.common.struts.ErrorCatchInterceptor">
   </interceptor>
   <interceptor-stack name="cctvInterStack">
    <interceptor-ref name="catchException"></interceptor-ref>
    <interceptor-ref name="defaultStack"></interceptor-ref>
   </interceptor-stack>
  </interceptors>
  <default-interceptor-ref name="cctvInterStack"></default-interceptor-ref> 
  <global-results>  
   <result name="ERROR">/common/page/error/errorpage.jsp</result>  
  </global-results>
 </package>

</struts>

struts文件结束

第三步 java操作类

package com.litsoft.cctv.twxt.common.dao;

import java.io.Serializable;

import java.util.List;

import com.litsoft.cctv.twxt.common.po.OaDept;

/**
 * 基本操作接口
 * @author silin.wang
 *
 */
public interface BaseDao {

/**
  * 批量插入数据
  *
  * @param l
  *            要插入的数据列表
  *
  */
 public void batchSave(List l) throws Exception;
 /**
  * 保存实例的方法
  *
  * @param obj
  *            需要保存的实例
  * @throws Exception
  *             hibernate异常
  */
 public void save(Object obj) throws Exception;
 /**
  * 保存实例并返回id
  *
  * @param obj
  *            需要保存的实例
  * @throws Exception
  *             hibernate异常
  */
 public Serializable saveAndReturnId(Object obj) throws Exception;
 /**
  * 批量更新数据
  *
  * @param l
  *            要更新的数据列表
  *
  */
 public void batchUpdate(List l) throws Exception;
 /**
  * 更新实例
  *
  * @param obj
  *            需要更新的实例
  */
 public void update(Object obj) throws Exception;
 /**
  * 插入或更新记录
  *
  * @param obj
  *            po对象
  */
 public void saveOrUpdate(Object obj) throws Exception;
 /**
  * 删除实例
  *
  * @param obj
  *            需要删除的实例
  */
 public void delete(Object obj) throws Exception;
 /**
  * 根据ID删除实例
  *
  * @param c
  *            实例的class
  * @param id
  *            实例id
  */
 public void deleteById(Class clazz, Long id) throws Exception;
 /**
  * 删除指定列在指定范围值内的所有记录
  *
  * @param clazz
  *            实体对象
  * @param pkName
  *            主键列名
  * @param idarray
  *            主键数组,注意数组长度不能大于5000,否则会报异常
  */
 public void deleteByIds(Class clazz, String pkName, Long[] idarray)
   throws Exception;
 /**
  * 根据ID得到一个实例
  *
  * @param c
  *            实例的class
  * @param id
  *            实例的id
  * @return
  */
 public Object getById(Class clazz, Serializable id) throws Exception;
 /**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            可直接执行的HQL语句
  * @return
  */
 public List queryByHql(String hql) throws Exception;
 /**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            可直接执行的HQL语句
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List queryByHql(String hql, int first, int max)throws Exception;
 /**
  * 单一对象组合条件查询结果列表
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @param orders
  *            排序条件列表(如:column_name desc;column_name asc)
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List querySingleObject(Class clazz, List<String> property,
   List params, List<String> orders, int first, int max)throws Exception;
 /**
  * 根据输入hql语句返回查询结果总数
  *
  * @param hql
  * @return
  */
 public int queryByHqlCount(String hql)throws Exception;
 /**
  * 单一对象组合条件查询结果总数
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @return
  */
 public int querySingleObjectCount(Class clazz, List<String> property,
   List params)throws Exception;
 /**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            带参数的HQL语句,参数数量应与params长度一致
  * @param params
  *            参数值列表
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List queryByHql(String hql, List params, int first, int max)throws Exception;
 /**
  * 根据输入HQL语句返回查询结果总数
  *
  * @param hql
  *            带参数的HQL语句,参数数量应与params长度一致
  * @param params
  *            参数值列表
  * @return
  */
 public int queryByHqlCount(String hql, List params)throws Exception;
 /**
  * 根据输入条件获得单一对象查询HQL语句
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @param orders
  *            排序条件列表(如:column_name desc;column_name asc)
  * @return
  */
 public String getHql(Class clazz, List<String> property, List<String> orders)throws Exception;
 /**
  * 查询某属性为指定值的记录是否存在, 存在返回true 不存在返回false
  *
  * @param Str
  * @return java.lang.Boolean
  */
 public boolean existType(Class clazz, String type, String key)throws Exception;
 /**
  * 获取指定表的sequence值
  *
  * @param sequenceName
  *            sequence名称
  *
  * @return sequence id
  */
 public Long getSID(String sequenceName)throws Exception;   
 public List<OaDept> queryOaDept(OaDept dept);
}

DAO实现

package com.litsoft.cctv.twxt.common.dao.impl;
import java.io.Serializable;

import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.litsoft.cctv.twxt.common.dao.BaseDao;
import com.litsoft.cctv.twxt.common.po.OaDept;

public class BaseDaoImpl extends HibernateDaoSupport implements BaseDao  {
    static Logger logger=Logger.getLogger(BaseDaoImpl.class);
    /**
  * 批量插入数据
  *
  * @param l
  *            要插入的数据列表
  *
  */
 public void batchSave(List l) throws Exception {
 
  try {
   for (int i = 0; i < l.size(); i++) {
    this.getHibernateTemplate().save(l.get(i));
    if ((i + 1) % 20 == 0) {
     this.getHibernateTemplate().flush();
    }
   }
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 保存实例的方法
  *
  * @param obj
  *            需要保存的实例
  * @throws Exception
  *             hibernate异常
  */
 public void save(Object obj) throws Exception {
  try {
   logger.debug("before save=>" + obj);
   this.getHibernateTemplate().save(obj);
   logger.debug("after save=>" + obj);
   //this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 保存实例并返回id
  *
  * @param obj
  *            需要保存的实例
  * @throws Exception
  *             hibernate异常
  */
 public Serializable saveAndReturnId(Object obj) throws Exception {
  Serializable id = null;
  try {
   id = this.getHibernateTemplate().save(obj);
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
  return id;
 }

/**
  * 批量更新数据
  *
  * @param l
  *            要更新的数据列表
  *
  */
 public void batchUpdate(List l) throws Exception {
  try {
   for (int i = 0; i < l.size(); i++) {
    this.getHibernateTemplate().update(l.get(i));
    if ((i + 1) % 20 == 0) {
     this.getHibernateTemplate().flush();
    }
   }
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 更新实例
  *
  * @param obj
  *            需要更新的实例
  */
 public void update(Object obj) throws Exception {
  try {
   this.getHibernateTemplate().update(obj);
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 插入或更新记录
  *
  * @param obj
  *            po对象
  */
 public void saveOrUpdate(Object obj) throws Exception {
  try {
   this.getHibernateTemplate().saveOrUpdate(obj);
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 删除实例
  *
  * @param obj
  *            需要删除的实例
  */
 public void delete(Object obj) throws Exception {
  try {
   this.getHibernateTemplate().delete(obj);
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 根据ID删除实例
  *
  * @param c
  *            实例的class
  * @param id
  *            实例id
  */
 public void deleteById(Class clazz, Long id) throws Exception {
  try {
   Object obj = this.getHibernateTemplate().load(clazz, id);
   this.getHibernateTemplate().delete(obj);
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 删除指定列在指定范围值内的所有记录
  *
  * @param clazz
  *            实体对象
  * @param pkName
  *            主键列名
  * @param idarray
  *            主键数组,注意数组长度不能大于5000,否则会报异常
  */
 public void deleteByIds(Class clazz, String pkName, Long[] idarray)
   throws Exception {
  String hql = "delete from " + clazz.getSimpleName() + " where "
    + pkName + " in (:idarray)";
  try {
   Query q = this.getSession().createQuery(hql);
   q.setParameterList("idarray", idarray);
   q.executeUpdate();
   this.getHibernateTemplate().flush();
  } catch (Exception e) {
   throw e;
  }
 }

/**
  * 根据ID得到一个实例
  *
  * @param c
  *            实例的class
  * @param id
  *            实例的id
  * @return
  */
 public Object getById(Class clazz, Serializable id) {
  Object obj = null;
  obj = this.getHibernateTemplate().get(clazz, id);
  return obj;
 }

/**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            可直接执行的HQL语句
  * @return
  */
 public List queryByHql(String hql) {
  return this.queryByHql(hql, null, -1, -1);
 }

/**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            可直接执行的HQL语句
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List queryByHql(String hql, int first, int max) {
  return this.queryByHql(hql, null, first, max);
 }

/**
  * 单一对象组合条件查询结果列表
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @param orders
  *            排序条件列表(如:column_name desc;column_name asc)
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List querySingleObject(Class clazz, List<String> property,
   List params, List<String> orders, int first, int max) {
  return queryByHql(getHql(clazz, property, orders), params, first, max);
 }

/**
  * 根据输入hql语句返回查询结果总数
  *
  * @param hql
  * @return
  */
 public int queryByHqlCount(String hql) {
  return this.queryByHqlCount(hql, null);
 }

/**
  * 单一对象组合条件查询结果总数
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @return
  */
 public int querySingleObjectCount(Class clazz, List<String> property,
   List params) {
  return this.queryByHqlCount(this.getHql(clazz, property, null), params);
 }

/**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            带参数的HQL语句,参数数量应与params长度一致
  * @param params
  *            参数值列表
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List queryByHql(String hql, List params, int first, int max) {
  // 生成query
  logger.debug(hql);
  Object obj = null;
  Query query = this.getSession().createQuery(hql);
  // 循环params
  if (params != null) {
   int n = params.size();
   for (int i = 0; i < n; i++) {
    obj = params.get(i);
    // 注意,query.setParameter是1序的
    logger.debug("params " + i + ":" + obj);

// this.getHql().append(
    // " and upper(" + this.getOtherName() + "." + fieldName
    // + ") like ? escape '/'");
    //
    // this.getParams().add(
    // "%"
    // + CommonTools.getLikeSelect(
    // fieldValue.toString()).toUpperCase()
    // + "%");

// if (obj instanceof String) {
    // obj = StringTool.getLikeSelect((String) obj).toUpperCase();
    // System.out.println(obj);
    // }
    query.setParameter(i, obj);
   }
  }
  // 设置页
  if (-1 != max) {
   query.setFirstResult(first);
   query.setMaxResults(max);
  }
  // 得到结果
  List list = query.list();
  return list;
 }

/**
  * 根据输入HQL语句返回查询结果总数
  *
  * @param hql
  *            带参数的HQL语句,参数数量应与params长度一致
  * @param params
  *            参数值列表
  * @return
  */
 public int queryByHqlCount(String hql, List params) {
  Object obj = null;
  String countHql = "select count(*) " + hql;
  // 生成query
  logger.debug(countHql);
  Query query = this.getSession().createQuery(countHql);
  // 循环params
  if (params != null) {
   int n = params.size();
   for (int i = 0; i < n; i++) {
    obj = params.get(i);
    // 注意,query.setParameter是1序的
    logger.debug("params " + i + ":" + obj);
    // if (obj instanceof String) {
    // obj = StringTool.getLikeSelect((String) obj).toUpperCase();
    // }
    query.setParameter(i, obj);
   }
  }
  
  // 得到结果
  //System.out.println(query.list().get(0));
  return ((Long) query.uniqueResult()).intValue();
 }

/**
  * 根据输入条件获得单一对象查询HQL语句
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @param orders
  *            排序条件列表(如:column_name desc;column_name asc)
  * @return
  */
 public String getHql(Class clazz, List<String> property, List<String> orders) {
  String c = clazz.getSimpleName();
  // 条件buffer
  StringBuffer str = new StringBuffer();
  String propertyValue = null;
  if (property != null) {
   // 首先循环property
   int n = property.size();
   for (int i = 0; i < n; i++) {
    propertyValue = property.get(i);
    if (propertyValue.contains("like")) {
     str.append(" and upper(");
     str.append(c);
     str.append(".");
     // .replaceFirst("=", ")=")
     str.append(propertyValue.replaceFirst(" like", ") like"));
    } else {
     str.append(" and ");
     str.append(c);
     str.append(".");
     // .replaceFirst("=", ")=")
     str.append(propertyValue);
    }
   }
  }
  if (orders != null) {
   int n = orders.size();
   for (int i = 0; i < n; i++) {
    if (i == 0)
     str.append(" order by ");
    else
     str.append(",");
    str.append(c);
    str.append(".");
    str.append(orders.get(i));
   }
  }
  // 后面一个c作为别名
  str.insert(0, " from " + c + " " + c + " where 1=1 ");
  return str.toString();
 }

/**
  * 查询某属性为指定值的记录是否存在, 存在返回true 不存在返回false
  *
  * @param Str
  * @return java.lang.Boolean
  */
 public boolean existType(Class clazz, String type, String key) {
  String strSql = " from " + clazz.getSimpleName() + " as a where a."
    + type + " = :type";
  Query q = this.getSession().createQuery(strSql);
  q.setString("type", key);
  List list = q.list();
  if (list.size() > 0) {
   return true;
  } else {
   return false;
  }
 }

/**
  * 获取指定表的sequence值
  *
  * @param sequenceName
  *            sequence名称
  *
  * @return sequence id
  */
 public Long getSID(String sequenceName) {
  Query query = this.getSession().createSQLQuery("select " + sequenceName
    + ".nextval FROM dual");
  return Long.valueOf(query.uniqueResult().toString());
 }

@Override
 public List<OaDept> queryOaDept(OaDept dept) {
  String hql="from OaDept dept where dept.parentid="+dept.getParentid();
  List list=this.getHibernateTemplate().find(hql);
  return list;
 }

}

业务模型接口

package com.litsoft.cctv.twxt.common.service;

import java.io.Serializable;

import java.util.List;

import com.litsoft.cctv.twxt.common.po.OaDept;

/**
 * 基本业务接口
 * @author silin.wang
 *
 */
public interface BaseService {

/**
  * 批量插入数据
  *
  * @param l
  *            要插入的数据列表
  *
  */
 public void batchSave(List l) throws Exception;
 /**
  * 保存实例的方法
  *
  * @param obj
  *            需要保存的实例
  * @throws Exception
  *             hibernate异常
  */
 public void save(Object obj) throws Exception;
 /**
  * 保存实例并返回id
  *
  * @param obj
  *            需要保存的实例
  * @throws Exception
  *             hibernate异常
  */
 public Serializable saveAndReturnId(Object obj) throws Exception;
 /**
  * 批量更新数据
  *
  * @param l
  *            要更新的数据列表
  *
  */
 public void batchUpdate(List l) throws Exception;
 /**
  * 更新实例
  *
  * @param obj
  *            需要更新的实例
  */
 public void update(Object obj) throws Exception;
 /**
  * 插入或更新记录
  *
  * @param obj
  *            po对象
  */
 public void saveOrUpdate(Object obj) throws Exception;
 /**
  * 删除实例
  *
  * @param obj
  *            需要删除的实例
  */
 public void delete(Object obj) throws Exception;
 /**
  * 根据ID删除实例
  *
  * @param c
  *            实例的class
  * @param id
  *            实例id
  */
 public void deleteById(Class clazz, Long id) throws Exception;
 /**
  * 删除指定列在指定范围值内的所有记录
  *
  * @param clazz
  *            实体对象
  * @param pkName
  *            主键列名
  * @param idarray
  *            主键数组,注意数组长度不能大于5000,否则会报异常
  */
 public void deleteByIds(Class clazz, String pkName, Long[] idarray)
   throws Exception;
 /**
  * 根据ID得到一个实例
  *
  * @param c
  *            实例的class
  * @param id
  *            实例的id
  * @return
  */
 public Object getById(Class clazz, Serializable id) throws Exception;
 /**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            可直接执行的HQL语句
  * @return
  */
 public List queryByHql(String hql) throws Exception;
 /**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            可直接执行的HQL语句
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List queryByHql(String hql, int first, int max)throws Exception;
 /**
  * 单一对象组合条件查询结果列表
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @param orders
  *            排序条件列表(如:column_name desc;column_name asc)
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List querySingleObject(Class clazz, List<String> property,
   List params, List<String> orders, int first, int max)throws Exception;
 /**
  * 根据输入hql语句返回查询结果总数
  *
  * @param hql
  * @return
  */
 public int queryByHqlCount(String hql)throws Exception;
 /**
  * 单一对象组合条件查询结果总数
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @return
  */
 public int querySingleObjectCount(Class clazz, List<String> property,
   List params)throws Exception;
 /**
  * 根据输入hql语句返回查询结果
  *
  * @param hql
  *            带参数的HQL语句,参数数量应与params长度一致
  * @param params
  *            参数值列表
  * @param first
  *            起始行
  * @param max
  *            总行数
  * @return
  */
 public List queryByHql(String hql, List params, int first, int max)throws Exception;
 /**
  * 根据输入HQL语句返回查询结果总数
  *
  * @param hql
  *            带参数的HQL语句,参数数量应与params长度一致
  * @param params
  *            参数值列表
  * @return
  */
 public int queryByHqlCount(String hql, List params)throws Exception;
 /**
  * 根据输入条件获得单一对象查询HQL语句
  *
  * @param clazz
  *            对象类型
  * @param property
  *            条件列表(如:column_name=?;column_name like ?)
  * @param params
  *            条件值列表
  * @param orders
  *            排序条件列表(如:column_name desc;column_name asc)
  * @return
  */
 public String getHql(Class clazz, List<String> property, List<String> orders)throws Exception;
 /**
  * 查询某属性为指定值的记录是否存在, 存在返回true 不存在返回false
  *
  * @param Str
  * @return java.lang.Boolean
  */
 public boolean existType(Class clazz, String type, String key)throws Exception;
 /**
  * 获取指定表的sequence值
  *
  * @param sequenceName
  *            sequence名称
  *
  * @return sequence id
  */
 public Long getSID(String sequenceName)throws Exception;
 public List<OaDept> queryOaDept(OaDept dept);

}

业务实现

package com.litsoft.cctv.twxt.common.service.impl;

import java.io.Serializable;
import java.util.List;
import com.litsoft.cctv.twxt.common.dao.BaseDao;
import com.litsoft.cctv.twxt.common.po.OaDept;
import com.litsoft.cctv.twxt.common.service.BaseService;
/**
 * 基本业务实现
 * @author silin.wang
 *
 */
public class BaseServiceImpl implements BaseService {
    private BaseDao baseDao;
   
 public void setBaseDao(BaseDao baseDao) {
  this.baseDao = baseDao;
 }

public void batchSave(List l) throws Exception {
  
  baseDao.batchSave(l);
 }

public void batchUpdate(List l) throws Exception {
  
  baseDao.batchUpdate(l);
 }

public void delete(Object obj) throws Exception {
  
  baseDao.delete(obj);
 }

public void deleteById(Class clazz, Long id) throws Exception {
  
  baseDao.deleteById(clazz, id);
 }

public void deleteByIds(Class clazz, String pkName, Long[] idarray)
   throws Exception {
  
  baseDao.deleteByIds(clazz, pkName, idarray);
 }

public boolean existType(Class clazz, String type, String key)
   throws Exception {
  
  return baseDao.existType(clazz, type, key);
 }

public Object getById(Class clazz, Serializable id) throws Exception {
  
  return baseDao.getById(clazz, id);
 }

public String getHql(Class clazz, List<String> property, List<String> orders)
   throws Exception {
  
  return baseDao.getHql(clazz, property, orders);
 }

public Long getSID(String sequenceName) throws Exception {
  
  return baseDao.getSID(sequenceName);
 }

public List queryByHql(String hql, int first, int max) throws Exception {
  
  return baseDao.queryByHql(hql, first, max);
 }

public List queryByHql(String hql, List params, int first, int max)
   throws Exception {
  
  return baseDao.queryByHql(hql, first, max);
 }

public List queryByHql(String hql) throws Exception {
  
  return baseDao.queryByHql(hql);
 }

public int queryByHqlCount(String hql, List params) throws Exception {
  
  return baseDao.queryByHqlCount(hql, params);
 }

public int queryByHqlCount(String hql) throws Exception {
  
  return baseDao.queryByHqlCount(hql);
 }

public List querySingleObject(Class clazz, List<String> property,
   List params, List<String> orders, int first, int max)
   throws Exception {
  
  return baseDao.querySingleObject(clazz, property, params, orders, first, max);
 }

public int querySingleObjectCount(Class clazz, List<String> property,
   List params) throws Exception {
  
  return baseDao.querySingleObjectCount(clazz, property, params);
 }

public void save(Object obj) throws Exception {
  
  baseDao.save(obj);
  
 }

public Serializable saveAndReturnId(Object obj) throws Exception {
  
  return baseDao.saveAndReturnId(obj);
 }

public void saveOrUpdate(Object obj) throws Exception {
  
  baseDao.saveOrUpdate(obj);
 }

public void update(Object obj) throws Exception {
  
  baseDao.update(obj);
 }

@Override
 public List<OaDept> queryOaDept(OaDept dept) {
  // TODO Auto-generated method stub
  return baseDao.queryOaDept(dept);
 }

}

继承重构ActionSupport

package com.litsoft.cctv.twxt.common.struts;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class BaseAction extends ActionSupport {
 /**
  *
  */
 private static final long serialVersionUID = -1470484361342972167L;

protected Log logger = LogFactory.getLog(this.getClass());
 protected HttpServletRequest request = ServletActionContext.getRequest();
 protected HttpServletResponse response = ServletActionContext.getResponse();
 protected HttpSession session = request.getSession();
 protected ServletContext application = ServletActionContext
   .getServletContext();
 protected String input_url = null;
 protected String forward_url = null;
 protected String redirect_url = null;
 private String messageCode;
 
 protected String forward(String url){
  this.forward_url = url;
  return "forward_url";
 }
 protected String redirect(String url){
  this.redirect_url = url;
  return "redirect_url";
 }

protected String urlname = null;
 protected String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + request.getContextPath() + "/";

protected PageInfo page = new PageInfo();

public void showMsg(String succMsg) {
  logger.debug("set succMsg in session:" + succMsg + "*");
  session.setAttribute("succMsg", succMsg);
 }

public PageInfo getPage() {
  return page;
 }

public void setPage(PageInfo page) {
  this.page = page;
 }

public String getUrlname() {
  return urlname;
 }

public void setUrlname(String urlname) {
  this.urlname = urlname;
 }

public String getInput_url() {
  return input_url;
 }

public void setInput_url(String input_url) {
  this.input_url = input_url;
 }

public String getForward_url() {
  return forward_url;
 }

public void setForward_url(String forward_url) {
  this.forward_url = forward_url;
 }

public String getRedirect_url() {
  return redirect_url;
 }

public void setRedirect_url(String redirect_url) {
  this.redirect_url = redirect_url;
 }
 public String getMessageCode() {
  return messageCode;
 }
 public void setMessageCode(String messageCode) {
  this.messageCode = messageCode;
 }

}

package com.litsoft.cctv.twxt.common.po;

import java.io.Serializable;

import com.litsoft.cctv.twxt.common.util.ObjectToString;

//import org.apache.commons.lang.builder.ToStringBuilder;

public class BaseModel implements Serializable {
 /**
  *
  */
 private static final long serialVersionUID = -8638327111782386253L;

public String toString() {
  // return ToStringBuilder.reflectionToString(this);
  // 避免ToStringBuilder引起List对象的嵌套循环调用导致堆栈溢出
  return ObjectToString.toStringBuilder(this);
 }
}

分页工具类

package com.litsoft.cctv.twxt.common.struts;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.litsoft.cctv.twxt.common.po.BaseModel;
import com.litsoft.cctv.twxt.common.util.MathTool;
public class PageInfo extends BaseModel {

/**
  *
  */
 private static final long serialVersionUID = 1314064453549547233L;

protected Log logger = LogFactory.getLog(this.getClass());

private int totalCount = 0; // 总记录数

private int totalPage = 0;// 总页数

private int pageIndex = 0;// 当前应显示页,默认为第0页,以便当初次请求时,返回第一行到maxResult行的数据

private int maxResult = 10;// 每页显示数

private int clearPage = 1;// 为0表示通过分页控件提交,不清空翻页记录,为1表示新提交请求,相关分页信息初始化

private int startIndex = 0;// 默认开始记录数

/**
  * 当设置总记录数时,将自动计算共有多少页及当前为第几页
  *
  * @param recordcount
  *            记录总数
  */
 public void setTotalCount(int totalCount) {
  this.setTotalCount(totalCount, this.maxResult);
 }

/**
  * 当设置总记录数时,将自动计算共有多少页及当前为第几页
  *
  * @param recordcount
  *            记录总数
  * @param recordperpage
  *            每页显示记录数
  */
 public void setTotalCount(int totalCount, int maxResult) {
  // 当设定每页显示数时,修改默认的每页显示行数(默认为10)
  if (maxResult > 0) {
   this.setMaxResult(maxResult);
  }
  this.totalCount = totalCount;
 }

/**
  * 得到分页的开始记录位置
  *
  * @return
  */
 public int getStartIndex() {
  if (this.totalCount < 0) {
   // 当前页为0,没有查询到记录
   this.startIndex = 0;
   return this.startIndex;
  }
  // 上取整获得总页数
  this.totalPage = MathTool.getDivInt(this.totalCount, this.maxResult);

if (this.clearPage == 1) {// 新的请求,重置起始页
   if (this.totalPage == 0) {
    this.pageIndex = 0;
   } else {
    this.pageIndex = 1;
   }
  } else {// 翻页请求,保留当前页信息
   if (this.pageIndex > this.totalPage)
    // 当前页大于totalpage,说明记录可能已经被删除,导致总页数减少,将currpage设置为当前最大页
    this.pageIndex = this.totalPage;
  }
  if (this.pageIndex > 0)
   this.startIndex = new Integer((this.pageIndex - 1) * this.maxResult)
     .intValue();
  else
   this.startIndex = 0;
  return this.startIndex;
 }

public void setTotalPage(int totalPage) {
  this.totalPage = totalPage;
 }

public int getPageIndex() {
  return pageIndex;
 }

public void setPageIndex(int pageIndex) {
  this.pageIndex = pageIndex;
 }

public int getMaxResult() {
  return maxResult;
 }

public void setMaxResult(int maxResult) {
  this.maxResult = maxResult;
 }

public int getTotalCount() {
  return totalCount;
 }

public int getTotalPage() {
  return totalPage;
 }

public int getClearPage() {
  return clearPage;
 }

public void setClearPage(int clearPage) {
  this.clearPage = clearPage;
 }
}

业务控制层模型

package com.litsoft.cctv.twxt.leaguemembermanage.ui.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import com.litsoft.cctv.twxt.common.po.OaDept;
import com.litsoft.cctv.twxt.common.service.BaseService;
import com.litsoft.cctv.twxt.common.struts.BaseAction;
import com.litsoft.cctv.twxt.leaguemembermanage.ui.form.UserForm;

public class UserManagerAction extends BaseAction implements Runnable  {
  
 
 private UserForm uForm;
 
 private BaseService baseService;
 
 private Long id;
 private static final long serialVersionUID = 1L;
 public void setBaseService(BaseService baseService) {
  this.baseService = baseService;
 }

public UserForm getuForm() {
  return uForm;
 }

public void setuForm(UserForm uForm) {
  this.uForm = uForm;
 }

public BaseService getBaseService() {
  return baseService;
 }

public Long getId() {
  return id;
 }

public void setId(Long id) {
  this.id = id;
 }

@SuppressWarnings("unchecked")
 public String list()throws Exception{
  LinkedList property = new LinkedList();
  LinkedList params = new LinkedList();
  property.add(uForm);
  logger.info(property.size());
  page.setTotalCount(baseService.queryByHqlCount("from OaUser"));
  LinkedList<String> orders = new LinkedList<String>();
  List userList=baseService.queryByHql("from OaUser", page.getStartIndex(), page.getMaxResult());
  request.setAttribute("userList", userList);
  return "success";
 }
 
 @SuppressWarnings("unchecked")
 public String query()throws Exception{
  List<OaDept> result=new ArrayList<OaDept>();
  List<OaDept> deptList=listOaDept(Long.valueOf("0"),result);
  String jsonString=this.formatJson(deptList);
  response.setContentType("text/json;charset=utf-8");
  PrintWriter out = response.getWriter();
  out.flush();
  out.println(jsonString);
  out.close();
  return null;
  
 }
 
 @SuppressWarnings("unchecked")
 public String query1()throws Exception{
  List<OaDept> result=new ArrayList<OaDept>();
  List<OaDept> deptList=listOaDept(Long.valueOf("0"),result);
  String jsonString=this.formatJson1(deptList);
     response.setContentType("text/json;charset=utf-8");
  PrintWriter out = response.getWriter();
  out.flush();
  out.println(jsonString);
  out.close();
  return null;
  
 }
 
 /**
  * 用户列表信息
  * @param id
  * @param deptList
  * @return
  * @throws Exception
  */
 public  List listOaDept(Long id,List<OaDept> deptList)throws Exception{
  OaDept dept=new OaDept();
  dept.setParentid(id);
     List<OaDept> oaDeptList=baseService.queryOaDept(dept);
     for(OaDept result:oaDeptList){
      System.out.print(result.getDeptname());
      deptList.add(result);
      listOaDept(result.getId(),deptList);
      
      
     }
  return deptList;
 }
 
 /**
  * 转换为json对象
  * @param deptList
  * @return
  * @throws Exception
  */
 private String formatJson(List<OaDept> deptList)throws Exception{
  JSONArray tree = new JSONArray();          
  for(OaDept dept:deptList){
   JSONObject node = new JSONObject();
   node.put("id",  dept.getId());
   node.put("pId", dept.getParentid());
   node.put("name",dept.getDeptname());
   tree.put(node);
    
  }
  return tree.toString();
 }
 
 /**
  * 转换为json对象
  * @param deptList
  * @return
  * @throws Exception
  */
 private String formatJson1(List<OaDept> deptList)throws Exception{
  JSONArray tree = new JSONArray();          
  for(OaDept dept:deptList){
   JSONObject node = new JSONObject();
   node.put("id",  dept.getId());
   node.put("pid", dept.getParentid());
   node.put("name",dept.getDeptname());
   tree.put(node);
    
  }
  return tree.toString();
 }

@Override
 public void run() {
  
  
 }

}

实体bean

package com.litsoft.cctv.twxt.common.po;
/**
 * 部门 模型
 * @author silin.wang
 *
 */
public class OaDept implements java.io.Serializable {

// Fields

private Long id; //主键
 private String deptname;//部门名称
 private String deptcode; //部门code
 private String treepath; //节点path
 private Short syscode; //部门级别
 private Long parentid; //上级节点
 private Short delflag; //删除标识
 // Constructors

/** default constructor */
 public OaDept() {
 }

/** full constructor */
 public OaDept(String deptname, String deptcode, String treepath,
   Short syscode, Long parentid, Short delflag) {
  this.deptname = deptname;
  this.deptcode = deptcode;
  this.treepath = treepath;
  this.syscode = syscode;
  this.parentid = parentid;
  this.delflag = delflag;
 }

// Property accessors

public Long getId() {
  return this.id;
 }

public void setId(Long id) {
  this.id = id;
 }

public String getDeptname() {
  return this.deptname;
 }

public void setDeptname(String deptname) {
  this.deptname = deptname;
 }

public String getDeptcode() {
  return this.deptcode;
 }

public void setDeptcode(String deptcode) {
  this.deptcode = deptcode;
 }

public String getTreepath() {
  return this.treepath;
 }

public void setTreepath(String treepath) {
  this.treepath = treepath;
 }

public Short getSyscode() {
  return this.syscode;
 }

public void setSyscode(Short syscode) {
  this.syscode = syscode;
 }

public Long getParentid() {
  return this.parentid;
 }

public void setParentid(Long parentid) {
  this.parentid = parentid;
 }

public Short getDelflag() {
  return this.delflag;
 }

public void setDelflag(Short delflag) {
  this.delflag = delflag;
 }

}

ztree.jsp实现ztree.js树形菜单

<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="c" uri="/common/tld/c.tld"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>树形菜单</title>
    <meta content="text/html; charset=UTF-8" http-equiv=Content-Type>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="部门">
 <meta http-equiv="description" content="部门管理">
 <link rel="stylesheet" type="text/css" href="<%=path%>/common/js/jquery/jqueryZtree3.1/css/zTreeStyle/zTreeStyle.css" type="text/css">
 <script type="text/javascript" src="<%=path%>/common/js/jquery/jquery-1.7.1.min.js"></script>
 <script type="text/javascript" src="<%=path%>/common/js/jquery/jqueryZtree3.1/js/jquery.ztree.core-3.1.min.js"></script>
 <script type="text/javascript" src="<%=path%>/common/js/jquery/jqueryZtree3.1/js/jquery.ztree.excheck-3.1.min.js"></script>
 <script type="text/javascript">
  var setting = {
           data: {
               key: {
                   title: "t"
               },
               simpleData: {
                   enable: true
               }
           },
           callback: {
               onClick: zTreeOnClick
           }
       };
       var zNodes;
       $(document).ready(function(){      
            refreshTree();   
       });
      
       function refreshTree() {
          $.getJSON('<%=path%>/leaguemembermanage_UserManagerAction_query.action',function(data){ 
                  
                    $.each(data,function(entryIndex,entry){ //循坏开始
                         zNodes=data;
                     });
                   // $("#treeDiv").html(tree.toString());
                   $.fn.zTree.init($("#treeDiv"), setting, zNodes);
                  
          
          });
      
       }
      
       function zTreeOnClick(){
      
      
       }
 
 </script>

</head>
 
  <body>
        <div class="dtree">    
           
             
              <div id="treeDiv">  
                   
              </div>
                    
        </div>
  </body>
</html>

dtree实现

<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="c" uri="/common/tld/c.tld"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>树形菜单</title>
    <meta content="text/html; charset=UTF-8" http-equiv=Content-Type>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="部门">
 <meta http-equiv="description" content="部门管理">
 <link href="common/css/style.css" rel="stylesheet" type="text/css">
 <link href="./common/js/dtree/dtree.css" rel="StyleSheet" type="text/css" />
 <link href="./common/css/litsoft_global_style.css" rel="stylesheet" type="text/css">
 <script type="text/javascript" src="./common/js/jquery-1.4.2.min.js"></script> 
 <script type="text/javascript" src="./common/js/My97DatePicker/WdatePicker.js"></script>
 <script type="text/javascript" src="./common/js/dtree/dtree.js"></script>
 <script type="text/javascript" src="./common/js/jquery-1.4.2.min.js"></script>
 <script type="text/javascript">
    var tree;
       $(document).ready(function(){      
            refreshTree();   
       });
      
       function refreshTree() {
          $.getJSON('<%=path%>/leaguemembermanage_UserManagerAction_query1.action',function(data){ 
                    tree = new dTree('tree');
                    tree.add(0,-1,'团务系统');    
                    $.each(data,function(entryIndex,entry){ //循坏开始
                         tree.add(entry['id'], entry['pid'], entry['name']);
                     });
                    $("#treeDiv").html(tree.toString());
          
          });
      
       }
 
 </script>

</head>
 
  <body>
        <div class="dtree">    
           
              <p><a href="javascript: tree.openAll();">open all</a> | <a href="javascript: tree.closeAll();">close all</a></p>      
              <div id="treeDiv">  
                   
              </div>
                    
        </div>
  </body>
</html>

如有需完整,请留言,或者发送邮箱454096624@qq.com。初次发表,新手,请勿喷!

转载于:https://my.oschina.net/u/238082/blog/111827

Struts2+Hibernate+Spring+ZTree+Dtree 实现树形菜单相关推荐

  1. Struts2+Hibernate+Spring 整合示例

    转自:https://blog.csdn.net/tkd03072010/article/details/7468769 Struts2+Hibernate+Spring 整合示例 Spring整合S ...

  2. dTree三级树形菜单

    dTree三级树形菜单,老外的东西,不过修改挺方便面的,你甚至可以把它改为动态读取数据库的,演示图在上边,是不是你想要的? http://www.codefans.net/soft/3451.shtm ...

  3. 【struts2+hibernate+spring项目实战】实现用户登录功能(ssh)

    一.概述 从今天才开始有时间来总结总结以前自己练习的一些东西,希望总结出来对以后可以更加便捷的来学习,也希望可以帮助到正需要这些东西的同行人,一起学习,共同进步. 二. 登录功能总结 2.1.登录功能 ...

  4. struts2+hibernate+spring配置详解

    #struts2+hibernate+spring配置详解 struts2+hibernate+spring配置详解 哎 ,当初一个人做好难,现在终于弄好了,希望自学这个的能少走些弯路. 以下是自己配 ...

  5. Struts2 + Hibernate + Spring 以及javaweb模块问题解决(1)

    Struts2 + Hibernate + Spring 以及javaweb模块问题解决 1.资源文件的配置:src文件夹里面要配置,action所在的目录中也要配置. 2.<s: action ...

  6. 关于如何利用Struts2,Hibernate,Spring开发电子商业汇票系统

    关于如何利用Struts2,Hibernate,Spring开发电子商业汇票系统. 首先先说说电子商业汇票的种类: 1.电子银行承兑汇票 2.电子商业承兑汇票 另外电子商业汇票与纸票的区别: 电子商业 ...

  7. SSH(Struts2+Hibernate+Spring)开发策略

    很多小伙伴可能一听到框架两个字就会马上摇头,脑子里立刻闪现一个词---"拒绝",其实我也不例外,但我想告诉大家的是,当你真正掌握它时,你会发现**SSH**用起来是那么顺手,因为它 ...

  8. SpringSecurity系列(四) Spring Security 实现权限树形菜单

    SpringSecurity系列(一) 初识 Spring Security SpringSecurity系列(二) Spring Security入门 SpringSecurity系列(三) Spr ...

  9. 【struts2+hibernate+spring项目实战】Spring计时器任务 Spring整合JavaMail(邮件发送)(ssh)

    一.常用数据频度维护 对于系统使用度较高的数据,客户在查看时希望这些数据最好先出现,此时需要为其添加排序规则.在进行排序时,使用次数成为排序的依据.因此需要设置一个字段用来描述某种数据的使用次数,也就 ...

最新文章

  1. Java中父类构造方法对子类构造方法的影响(不是一句话可以说清的)
  2. android 8 esp8266,ESP8266 WIFI模块学习之路(8)——自写Android手机APP控制直流电机正反转...
  3. android:textAppearance
  4. Linux 文件查找命令
  5. 修改vsftpd的默认根目录/var/ftp/pub到另一个目录
  6. JavaScript 中的常用12种循环遍历(数组或对象)的方法
  7. 6.求级数e = 1 + 1/1! + 1/2! + 1/3! + …… 1/n! 要求: 求n项(n由键盘输入)或最后一项小于10-6结束。
  8. Linux下备份cisco路由配置
  9. [转]nginx反向代理网站(网易、百度之类的)
  10. vb6编写dll读取dat文件_【STM32Cube_15】使用硬件I2C读取温湿度传感器数据(SHT30)...
  11. Downloader Middlewares反反爬虫【学习笔记04】
  12. 示波器纹波测试的时间设置_500W电源横评:输出纹波3款电源超标
  13. tuxedo 强制重启
  14. JAVE 视音频转码
  15. IntelliJ IDEA教程()ideaIU-快速创建测试用例
  16. C语言链表详解(通俗易懂,超详细)
  17. CC3200+TB6612FNG 驱动电机实现开环控制
  18. 简洁但功能强大的EditPlus UltraEdit
  19. 软件安装【持续更新ing】
  20. ctime(ctime头文件的作用)

热门文章

  1. 并行计算与集群技术(2)
  2. 简述中断处理的6个步骤_完整的中断处理过程分为那几个阶段?
  3. Padavan固件免流,能连接成功暂时没测成功免流没有
  4. 印象笔记(evernote)支持MarkDown语法
  5. Python正则表达式在线练习(网页版)和离线练习(本地版)
  6. C语言 IP地址的转换
  7. uniapp中上传图片
  8. 产品功能留存分析矩阵
  9. 由“西游记”的唐僧扫塔想到的
  10. html文本怎么转化为数字html,将阿拉伯数字转换为html文件中的阿拉伯/波斯数字...