`

SSH1整合下的通用泛型DAO+分页,基于HibernateTemplate

阅读更多

个人也是初学SSH,这也是对以前我发布的通用泛型DAO的一个升级(J2EE学习笔记——初试SSH之泛型通用DAO

 

共包含3个类:BaseHibernateDAO,Page,QueryParameter

 

BaseHibernateDAO.java

 

Java代码 复制代码
  1. /**  
  2.  * DAO操作基类<br>  
  3.  * 本DAO层实现了通用的数据操作  
  4.  *   
  5.  * @author 黄磊  
  6.  *   
  7.  * @param <T>  
  8.  *            POJO实体对象  
  9.  * @param <ID>  
  10.  *            ID  
  11.  */  
  12. @SuppressWarnings("unchecked")   
  13. public class BaseHibernateDAO<T, ID extends Serializable> extends  
  14.         HibernateDaoSupport {   
  15.   
  16.     private static final Logger logger = Logger   
  17.             .getLogger(BaseHibernateDAO.class);   
  18.   
  19.     /**  
  20.      * 保存指定实体类  
  21.      *   
  22.      * @param entityobj  
  23.      *            实体类  
  24.      */  
  25.     public void save(T entity) {   
  26.         try {   
  27.             getHibernateTemplate().save(entity);   
  28.             if (logger.isDebugEnabled()) {   
  29.                 logger.debug("保存实体类成功," + entity.getClass().getName());   
  30.             }   
  31.         } catch (RuntimeException e) {   
  32.             logger.error("保存实体异常," + entity.getClass().getName(), e);   
  33.             throw e;   
  34.         }   
  35.     }   
  36.   
  37.     /**  
  38.      * 删除指定实体  
  39.      *   
  40.      * @param entityobj  
  41.      *            实体类  
  42.      */  
  43.     public void delete(T entity) {   
  44.         try {   
  45.             getHibernateTemplate().delete(entity);   
  46.             if (logger.isDebugEnabled()) {   
  47.                 logger.debug("删除实体类成功," + entity.getClass().getName());   
  48.             }   
  49.         } catch (RuntimeException e) {   
  50.             logger.error("删除实体异常", e);   
  51.             throw e;   
  52.         }   
  53.     }   
  54.   
  55.     /**  
  56.      * 获取所有实体集合  
  57.      *   
  58.      * @param entityClass  
  59.      *            实体  
  60.      * @return 集合  
  61.      */  
  62.     public List<T> findAll(Class<T> entityClass) {   
  63.         try {   
  64.             if (logger.isDebugEnabled()) {   
  65.                 logger.debug("开始删除实体:" + entityClass.getName());   
  66.             }   
  67.             return getHibernateTemplate().find("from " + entityClass.getName());   
  68.         } catch (RuntimeException e) {   
  69.             logger.error("查找指定实体集合异常,实体:" + entityClass.getName(), e);   
  70.             throw e;   
  71.         }   
  72.     }   
  73.   
  74.     /**  
  75.      * 更新或保存指定实体  
  76.      *   
  77.      * @param entity  
  78.      *            实体类  
  79.      */  
  80.     public void saveOrUpdate(T entity) {   
  81.         try {   
  82.             getHibernateTemplate().saveOrUpdate(entity);   
  83.             if (logger.isDebugEnabled()) {   
  84.                 logger.debug("更新或者保存实体成功," + entity.getClass().getName());   
  85.             }   
  86.         } catch (RuntimeException e) {   
  87.             logger.error("更新或保存实体异常", e);   
  88.             throw e;   
  89.         }   
  90.     }   
  91.   
  92.     /**  
  93.      * 查找指定ID实体类对象  
  94.      *   
  95.      * @param entityClass  
  96.      *            实体Class  
  97.      * @param id  
  98.      *            实体ID  
  99.      * @return 实体对象  
  100.      */  
  101.     public T findById(Class<T> entityClass, ID id) {   
  102.         try {   
  103.             if (logger.isDebugEnabled()) {   
  104.                 logger.debug("开始查找ID为" + id + "的实体:" + entityClass.getName());   
  105.             }   
  106.             return (T) getHibernateTemplate().get(entityClass, id);   
  107.         } catch (RuntimeException e) {   
  108.             logger.error("查找指定ID实体异常,ID:" + id, e);   
  109.             throw e;   
  110.         }   
  111.     }   
  112.   
  113.     /**  
  114.      * 查询指定HQL,并返回集合  
  115.      *   
  116.      * @param hql  
  117.      *            HQL语句  
  118.      * @param values  
  119.      *            可变的参数列表  
  120.      * @return 集合  
  121.      */  
  122.     public List<Object> find(String hql, Object... values) {   
  123.         try {   
  124.             if (logger.isDebugEnabled()) {   
  125.                 logger.debug("开始查询指定HQL语句," + hql);   
  126.             }   
  127.             return getHibernateTemplate().find(hql, values);   
  128.         } catch (RuntimeException e) {   
  129.             logger.error("查询指定HQL异常,HQL:" + hql, e);   
  130.             throw e;   
  131.         }   
  132.     }   
  133.   
  134.     /**  
  135.      * 按照HQL语句查询唯一对象.  
  136.      *   
  137.      * @param hql  
  138.      *            HQL语句  
  139.      * @param values  
  140.      *            可变参数集合  
  141.      * @return OBJECT对象  
  142.      */  
  143.     public Object findUnique(final String hql, final Object... values) {   
  144.         try {   
  145.             if (logger.isDebugEnabled()) {   
  146.                 logger.debug("开始查询返回唯一结果的HQL语句," + hql);   
  147.             }   
  148.             return getHibernateTemplate().execute(new HibernateCallback() {   
  149.                 public Object doInHibernate(Session s)   
  150.                         throws HibernateException, SQLException {   
  151.                     Query query = createQuery(s, hql, values);   
  152.                     return query.uniqueResult();   
  153.                 }   
  154.             });   
  155.         } catch (RuntimeException e) {   
  156.             logger.error("查询指定HQL异常,HQL:" + hql, e);   
  157.             throw e;   
  158.         }   
  159.     }   
  160.   
  161.     /**  
  162.      * 查找指定HQL并返回INT型  
  163.      *   
  164.      * @param hql  
  165.      *            HQL语句  
  166.      * @param values  
  167.      *            可变参数列表  
  168.      * @return INT  
  169.      */  
  170.     public int findInt(final String hql, final Object... values) {   
  171.         return Tools.null2Int(findUnique(hql, values));   
  172.     }   
  173.   
  174.     /**  
  175.      * 获取指定实体Class指定条件的记录总数  
  176.      *   
  177.      * @param entityClass  
  178.      *            实体Class  
  179.      * @param where  
  180.      *            HQL的查询条件,支持参数列表  
  181.      * @param values  
  182.      *            可变参数列表  
  183.      * @return 记录总数  
  184.      */  
  185.     public int findTotalCount(Class<T> entityClass, final String where,   
  186.             final Object... values) {   
  187.         String hql = "select count(e) from " + entityClass.getName() + " as e "  
  188.                 + where;   
  189.         return findInt(hql, values);   
  190.     }   
  191.   
  192.     /**  
  193.      * 获取指定实体Class的记录总数  
  194.      *   
  195.      * @param entityClass  
  196.      *            实体Class  
  197.      * @return 记录总数  
  198.      */  
  199.     public int findTotalCount(Class<T> entityClass) {   
  200.         return findTotalCount(entityClass, "");   
  201.     }   
  202.   
  203.     /**  
  204.      * 查找指定属性的实体集合  
  205.      *   
  206.      * @param entityClass  
  207.      *            实体  
  208.      * @param propertyName  
  209.      *            属性名  
  210.      * @param value  
  211.      *            条件  
  212.      * @return 实体集合  
  213.      */  
  214.     public List<T> findByProperty(Class<T> entityClass, String propertyName,   
  215.             Object value) {   
  216.         try {   
  217.             if (logger.isDebugEnabled()) {   
  218.                 logger.debug("开始查找指定属性:" + propertyName + "为" + value + "的实体"  
  219.                         + entityClass.getName());   
  220.             }   
  221.             String queryStr = "from " + entityClass.getName()   
  222.                     + " as model where model." + propertyName + "=?";   
  223.             return getHibernateTemplate().find(queryStr, value);   
  224.         } catch (RuntimeException e) {   
  225.             logger.error("查找指定条件实体集合异常,条件:" + propertyName, e);   
  226.             throw e;   
  227.         }   
  228.     }   
  229.   
  230.     /**  
  231.      * 模糊查询指定条件对象集合 <br>  
  232.      * 用法:可以实例化一个空的T对象,需要查询某个字段,就set该字段的条件然后调用本方法<br>  
  233.      * 缺点:目前测试貌似只能支持String的模糊查询,虽然有办法重写,但没必要,其他用HQL<br>  
  234.      *   
  235.      * @param entity  
  236.      *            条件实体  
  237.      * @return 结合  
  238.      */  
  239.     public List<T> findByExample(T entity) {   
  240.         try {   
  241.             List<T> results = getHibernateTemplate().findByExample(entity);   
  242.             return results;   
  243.         } catch (RuntimeException re) {   
  244.             logger.error("查找指定条件实体集合异常", re);   
  245.             throw re;   
  246.         }   
  247.     }   
  248.   
  249.     /**  
  250.      * 补充方法(未测) 据说可以无视session的状态持久化对象  
  251.      *   
  252.      * @param entity  
  253.      *            实体类  
  254.      * @return 持久后的实体类  
  255.      */  
  256.     public T merge(T entity) {   
  257.         try {   
  258.             T result = (T) getHibernateTemplate().merge(entity);   
  259.             return result;   
  260.         } catch (RuntimeException re) {   
  261.             logger.error("merge异常", re);   
  262.             throw re;   
  263.         }   
  264.     }   
  265.   
  266.     /**  
  267.      * 清除实体的锁定状态<br>  
  268.      * 方法未测  
  269.      *   
  270.      * @param entity  
  271.      *            实体  
  272.      */  
  273.     public void attachClean(T entity) {   
  274.         try {   
  275.             getHibernateTemplate().lock(entity, LockMode.NONE);   
  276.         } catch (RuntimeException re) {   
  277.             logger.error("实体解锁异常", re);   
  278.             throw re;   
  279.         }   
  280.     }   
  281.   
  282.     /**  
  283.      * 按HQL分页查询.  
  284.      *   
  285.      * @param page  
  286.      *            页面对象  
  287.      * @param hql  
  288.      *            HQL语句  
  289.      * @param values  
  290.      *            可变参数列表  
  291.      * @return 分页数据  
  292.      */  
  293.     public Page<T> findByPage(final Page<T> page, final String hql,   
  294.             final Object... values) {   
  295.         try {   
  296.             if (logger.isDebugEnabled()) {   
  297.                 logger.debug("开始查找指定HQL分页数据," + hql);   
  298.             }   
  299.             return (Page<T>) getHibernateTemplate().execute(   
  300.                     new HibernateCallback() {   
  301.                         public Object doInHibernate(Session s)   
  302.                                 throws HibernateException, SQLException {   
  303.                             Query query = createQuery(s, hql, values);   
  304.                             if (page.isFirstSetted()) {   
  305.                                 query.setFirstResult(page.getFirst());   
  306.                             }   
  307.                             if (page.isPageSizeSetted()) {   
  308.                                 query.setMaxResults(page.getPageSize());   
  309.                             }   
  310.                             page.setResult(query.list());   
  311.                             if (logger.isDebugEnabled()) {   
  312.                                 logger.debug("查找指定HQL分页数据成功," + hql);   
  313.                             }   
  314.                             return page;   
  315.                         }   
  316.                     });   
  317.         } catch (RuntimeException e) {   
  318.             logger.error("分页查询异常,HQL:" + hql, e);   
  319.             throw e;   
  320.         }   
  321.     }   
  322.   
  323.     /**  
  324.      * 根据查询条件与参数列表创建Query对象  
  325.      *   
  326.      * @param session  
  327.      *            Hibernate会话  
  328.      * @param hql  
  329.      *            HQL语句  
  330.      * @param objects  
  331.      *            参数列表  
  332.      * @return Query对象  
  333.      */  
  334.     public Query createQuery(Session session, String hql, Object... objects) {   
  335.         Query query = session.createQuery(hql);   
  336.         if (objects != null) {   
  337.             for (int i = 0; i < objects.length; i++) {   
  338.                 query.setParameter(i, objects[i]);   
  339.             }   
  340.         }   
  341.         return query;   
  342.     }   
  343.   
  344.     /**  
  345.      * 从Spring上下文中获取本类对象<br>  
  346.      * 此方法可能存在线程并发问题(待测)  
  347.      *   
  348.      * @param context  
  349.      *            Spring上下文  
  350.      * @return 本类对象  
  351.      */  
  352.     public static BaseHibernateDAO getFromApplicationContext(   
  353.             WebApplicationContext context) {   
  354.         return (BaseHibernateDAO) context.getBean("BaseHibernateDAO");   
  355.     }   
  356.   
  357. }  
/**
 * DAO操作基类<br>
 * 本DAO层实现了通用的数据操作
 * 
 * @author 黄磊
 * 
 * @param <T>
 *            POJO实体对象
 * @param <ID>
 *            ID
 */
@SuppressWarnings("unchecked")
public class BaseHibernateDAO<T, ID extends Serializable> extends
		HibernateDaoSupport {

	private static final Logger logger = Logger
			.getLogger(BaseHibernateDAO.class);

	/**
	 * 保存指定实体类
	 * 
	 * @param entityobj
	 *            实体类
	 */
	public void save(T entity) {
		try {
			getHibernateTemplate().save(entity);
			if (logger.isDebugEnabled()) {
				logger.debug("保存实体类成功," + entity.getClass().getName());
			}
		} catch (RuntimeException e) {
			logger.error("保存实体异常," + entity.getClass().getName(), e);
			throw e;
		}
	}

	/**
	 * 删除指定实体
	 * 
	 * @param entityobj
	 *            实体类
	 */
	public void delete(T entity) {
		try {
			getHibernateTemplate().delete(entity);
			if (logger.isDebugEnabled()) {
				logger.debug("删除实体类成功," + entity.getClass().getName());
			}
		} catch (RuntimeException e) {
			logger.error("删除实体异常", e);
			throw e;
		}
	}

	/**
	 * 获取所有实体集合
	 * 
	 * @param entityClass
	 *            实体
	 * @return 集合
	 */
	public List<T> findAll(Class<T> entityClass) {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("开始删除实体:" + entityClass.getName());
			}
			return getHibernateTemplate().find("from " + entityClass.getName());
		} catch (RuntimeException e) {
			logger.error("查找指定实体集合异常,实体:" + entityClass.getName(), e);
			throw e;
		}
	}

	/**
	 * 更新或保存指定实体
	 * 
	 * @param entity
	 *            实体类
	 */
	public void saveOrUpdate(T entity) {
		try {
			getHibernateTemplate().saveOrUpdate(entity);
			if (logger.isDebugEnabled()) {
				logger.debug("更新或者保存实体成功," + entity.getClass().getName());
			}
		} catch (RuntimeException e) {
			logger.error("更新或保存实体异常", e);
			throw e;
		}
	}

	/**
	 * 查找指定ID实体类对象
	 * 
	 * @param entityClass
	 *            实体Class
	 * @param id
	 *            实体ID
	 * @return 实体对象
	 */
	public T findById(Class<T> entityClass, ID id) {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("开始查找ID为" + id + "的实体:" + entityClass.getName());
			}
			return (T) getHibernateTemplate().get(entityClass, id);
		} catch (RuntimeException e) {
			logger.error("查找指定ID实体异常,ID:" + id, e);
			throw e;
		}
	}

	/**
	 * 查询指定HQL,并返回集合
	 * 
	 * @param hql
	 *            HQL语句
	 * @param values
	 *            可变的参数列表
	 * @return 集合
	 */
	public List<Object> find(String hql, Object... values) {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("开始查询指定HQL语句," + hql);
			}
			return getHibernateTemplate().find(hql, values);
		} catch (RuntimeException e) {
			logger.error("查询指定HQL异常,HQL:" + hql, e);
			throw e;
		}
	}

	/**
	 * 按照HQL语句查询唯一对象.
	 * 
	 * @param hql
	 *            HQL语句
	 * @param values
	 *            可变参数集合
	 * @return OBJECT对象
	 */
	public Object findUnique(final String hql, final Object... values) {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("开始查询返回唯一结果的HQL语句," + hql);
			}
			return getHibernateTemplate().execute(new HibernateCallback() {
				public Object doInHibernate(Session s)
						throws HibernateException, SQLException {
					Query query = createQuery(s, hql, values);
					return query.uniqueResult();
				}
			});
		} catch (RuntimeException e) {
			logger.error("查询指定HQL异常,HQL:" + hql, e);
			throw e;
		}
	}

	/**
	 * 查找指定HQL并返回INT型
	 * 
	 * @param hql
	 *            HQL语句
	 * @param values
	 *            可变参数列表
	 * @return INT
	 */
	public int findInt(final String hql, final Object... values) {
		return Tools.null2Int(findUnique(hql, values));
	}

	/**
	 * 获取指定实体Class指定条件的记录总数
	 * 
	 * @param entityClass
	 *            实体Class
	 * @param where
	 *            HQL的查询条件,支持参数列表
	 * @param values
	 *            可变参数列表
	 * @return 记录总数
	 */
	public int findTotalCount(Class<T> entityClass, final String where,
			final Object... values) {
		String hql = "select count(e) from " + entityClass.getName() + " as e "
				+ where;
		return findInt(hql, values);
	}

	/**
	 * 获取指定实体Class的记录总数
	 * 
	 * @param entityClass
	 *            实体Class
	 * @return 记录总数
	 */
	public int findTotalCount(Class<T> entityClass) {
		return findTotalCount(entityClass, "");
	}

	/**
	 * 查找指定属性的实体集合
	 * 
	 * @param entityClass
	 *            实体
	 * @param propertyName
	 *            属性名
	 * @param value
	 *            条件
	 * @return 实体集合
	 */
	public List<T> findByProperty(Class<T> entityClass, String propertyName,
			Object value) {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("开始查找指定属性:" + propertyName + "为" + value + "的实体"
						+ entityClass.getName());
			}
			String queryStr = "from " + entityClass.getName()
					+ " as model where model." + propertyName + "=?";
			return getHibernateTemplate().find(queryStr, value);
		} catch (RuntimeException e) {
			logger.error("查找指定条件实体集合异常,条件:" + propertyName, e);
			throw e;
		}
	}

	/**
	 * 模糊查询指定条件对象集合 <br>
	 * 用法:可以实例化一个空的T对象,需要查询某个字段,就set该字段的条件然后调用本方法<br>
	 * 缺点:目前测试貌似只能支持String的模糊查询,虽然有办法重写,但没必要,其他用HQL<br>
	 * 
	 * @param entity
	 *            条件实体
	 * @return 结合
	 */
	public List<T> findByExample(T entity) {
		try {
			List<T> results = getHibernateTemplate().findByExample(entity);
			return results;
		} catch (RuntimeException re) {
			logger.error("查找指定条件实体集合异常", re);
			throw re;
		}
	}

	/**
	 * 补充方法(未测) 据说可以无视session的状态持久化对象
	 * 
	 * @param entity
	 *            实体类
	 * @return 持久后的实体类
	 */
	public T merge(T entity) {
		try {
			T result = (T) getHibernateTemplate().merge(entity);
			return result;
		} catch (RuntimeException re) {
			logger.error("merge异常", re);
			throw re;
		}
	}

	/**
	 * 清除实体的锁定状态<br>
	 * 方法未测
	 * 
	 * @param entity
	 *            实体
	 */
	public void attachClean(T entity) {
		try {
			getHibernateTemplate().lock(entity, LockMode.NONE);
		} catch (RuntimeException re) {
			logger.error("实体解锁异常", re);
			throw re;
		}
	}

	/**
	 * 按HQL分页查询.
	 * 
	 * @param page
	 *            页面对象
	 * @param hql
	 *            HQL语句
	 * @param values
	 *            可变参数列表
	 * @return 分页数据
	 */
	public Page<T> findByPage(final Page<T> page, final String hql,
			final Object... values) {
		try {
			if (logger.isDebugEnabled()) {
				logger.debug("开始查找指定HQL分页数据," + hql);
			}
			return (Page<T>) getHibernateTemplate().execute(
					new HibernateCallback() {
						public Object doInHibernate(Session s)
								throws HibernateException, SQLException {
							Query query = createQuery(s, hql, values);
							if (page.isFirstSetted()) {
								query.setFirstResult(page.getFirst());
							}
							if (page.isPageSizeSetted()) {
								query.setMaxResults(page.getPageSize());
							}
							page.setResult(query.list());
							if (logger.isDebugEnabled()) {
								logger.debug("查找指定HQL分页数据成功," + hql);
							}
							return page;
						}
					});
		} catch (RuntimeException e) {
			logger.error("分页查询异常,HQL:" + hql, e);
			throw e;
		}
	}

	/**
	 * 根据查询条件与参数列表创建Query对象
	 * 
	 * @param session
	 *            Hibernate会话
	 * @param hql
	 *            HQL语句
	 * @param objects
	 *            参数列表
	 * @return Query对象
	 */
	public Query createQuery(Session session, String hql, Object... objects) {
		Query query = session.createQuery(hql);
		if (objects != null) {
			for (int i = 0; i < objects.length; i++) {
				query.setParameter(i, objects[i]);
			}
		}
		return query;
	}

	/**
	 * 从Spring上下文中获取本类对象<br>
	 * 此方法可能存在线程并发问题(待测)
	 * 
	 * @param context
	 *            Spring上下文
	 * @return 本类对象
	 */
	public static BaseHibernateDAO getFromApplicationContext(
			WebApplicationContext context) {
		return (BaseHibernateDAO) context.getBean("BaseHibernateDAO");
	}

}

  

QueryParameter.java

 

Java代码 复制代码
  1. /**  
  2.  * 本类封装分页和排序查询请求参数.  
  3.  * 本类参考自springside的ORM封装设计  
  4.  *   
  5.  *   
  6.  *   
  7.  */  
  8. public class QueryParameter {   
  9.        
  10.     public static final String ASC = "asc";   
  11.     public static final String DESC = "desc";   
  12.   
  13.     protected int pageNo = 1;   
  14.     protected int pageSize = -1;   
  15.     protected String orderBy = null;   
  16.     protected String order = ASC;   
  17.     protected boolean autoCount = false;   
  18.   
  19.     /**  
  20.      * 获得每页的记录数量,无默认值.  
  21.      */  
  22.     public int getPageSize() {   
  23.         return pageSize;   
  24.     }   
  25.   
  26.     public void setPageSize(int pageSize) {   
  27.         this.pageSize = pageSize;   
  28.     }   
  29.   
  30.     /**  
  31.      * 是否已设置每页的记录数量.  
  32.      */  
  33.     public boolean isPageSizeSetted() {   
  34.         return pageSize > -1;   
  35.     }   
  36.   
  37.     /**  
  38.      * 获得当前页的页号,序号从1开始,默认为1.  
  39.      */  
  40.     public int getPageNo() {   
  41.         return pageNo;   
  42.     }   
  43.   
  44.     public void setPageNo(int pageNo) {   
  45.         this.pageNo = pageNo;   
  46.     }   
  47.   
  48.     /**  
  49.      * 根据pageNo和pageSize计算当前页第一条记录在总结果集中的位置,序号从0开始.  
  50.      */  
  51.     public int getFirst() {   
  52.         if (pageNo < 1 || pageSize < 1)   
  53.             return -1;   
  54.         else  
  55.             return ((pageNo - <span styl
    分享到:
    评论

相关推荐

    ssh整合下的通用泛型DAO+分页

    在这个特定的讨论中,我们聚焦于SSH1中的一个关键概念:通用泛型DAO(Data Access Object)以及分页功能的实现。DAO层是模型层和数据访问层之间的桥梁,它的主要职责是处理数据库操作,为业务层提供无状态的数据访问...

    SSH泛型DAO+Proxool+DisPlayTag+Jquery easyui

    标题中的"SSH泛型DAO+Proxool+DisPlayTag+Jquery easyui"涉及到的是一个基于Spring、Struts和Hibernate(SSH)框架的Web应用开发中的几个关键技术和组件。让我们逐一深入探讨这些技术。 1. **Spring**: Spring 是...

    java底层代码:泛型DAO+SSH+Proxool连接池+国际化语言

    1、基于ssh的底层代码,可以用于开发各种web系统。 2、采用Jsp-&gt;Action-&gt;Service-&gt;Dao的编码方式,封装了HibernateUtil、SpringUtil、HqlUtil等工具,以及简化了增删查改操作。 3、此底层包含泛型DAO、Proxool连接池...

    ssh通用泛型DAO

    总的来说,"ssh通用泛型DAO"是一种设计模式,旨在简化SSH框架下的数据访问层开发,提高代码复用性,减少重复工作,同时通过泛型提供类型安全的保障。理解和熟练运用这一模式,能够有效地提升Java Web应用的开发效率...

    SSH2全注解整合(spring2.5+hibernate3.3+struts2.1+泛型DAO+proxool连接池)

    泛型DAO(Data Access Object)是一种设计模式,用于抽象数据访问层的操作,提供通用的CRUD(Create, Read, Update, Delete)方法。通过泛型,DAO可以适用于多种类型的实体,降低了代码重复。例如,一个BaseDAO接口...

    SSH 泛型DAO分页

    这个压缩包文件的标题"SSH 泛型DAO分页"表明它提供了一个实现SSH框架整合的示例,特别关注了泛型DAO(Data Access Object)以及分页功能。下面将详细介绍SSH框架及其分页和泛型DAO的概念。 1. **Struts2**: Struts2...

    泛型dao 泛型dao 泛型dao

    Struts2、Hibernate、Spring整合的泛型DAO (本人评价: 代码开发效率提高30% 代码出错率减少70%) 对于大多数开发人员,系统中的每个 DAO 编写几乎相同的代码到目前为止已经成为一种习惯。虽然所有人都将这种重复...

    JdbcTemplate通用泛型Dao实现

    本文将深入探讨`JdbcTemplate`通用泛型Dao实现的相关知识点,帮助开发者更好地理解和应用这一技术。 首先,让我们了解什么是`JdbcTemplate`。它是Spring框架的一部分,用于处理SQL操作。`JdbcTemplate`提供了一组...

    一个很好的通用泛型dao(含源码)

    为什么我们要使用通用DAO接口呢,因为我们的数据库操作无非是增删改查,CRUD操作,我们不需要为每个实体去编写一个dao接口,对于相似的实体操作可以只编写一个通用接口,然后采用不同的实现! DAO已经成为持久层...

    经典泛型dao层代码,非常好用简易

    ### 泛型DAO层在SSH框架中的应用与详解 #### 引言 在现代软件开发中,特别是基于Java的企业级应用开发中,DAO(Data Access Object)层的设计扮演着至关重要的角色。它作为业务逻辑层与数据持久层之间的桥梁,承担...

    Hibernate泛型Dao

    【描述】"基于hibernate5 泛型Dao实例,下载后改一下数据库配置直接可以用",意味着这个压缩包文件提供了一个已经实现好的Hibernate5版本的泛型Dao示例项目。用户只需要根据自己的数据库环境修改相应的配置信息,就...

    ssh2 + dao泛型

    这篇博客"ssh2 + dao泛型"结合了这两个概念,探讨了如何在SSH2框架下利用泛型优化DAO层的操作。 SSH2框架主要由Spring、Struts和Hibernate三个部分组成,它为Java Web开发提供了强大的支持。Spring提供依赖注入和...

    ssh通用基于泛型的dao

    标题“ssh通用基于泛型的dao”指的是使用SSH(Spring、Struts2、Hibernate)框架开发的一个通用的、基于泛型的DAO实现,它旨在提高开发效率,减少重复工作。 SSH框架是Java企业级应用开发的常用组合,Spring提供了...

    Hibernate泛型DAO(结合spring模板支持)

    泛型DAO是一种设计模式,它通过定义一个通用的DAO接口或抽象类,可以适用于不同的实体类,减少了重复的代码。这种模式的核心在于利用Java的泛型特性,使得DAO方法可以处理任何类型的实体对象,而无需为每个实体类...

    S2SH整合例子 注解配置 JSON 泛型Dao

    1. **Struts2**:Struts2是一个基于MVC设计模式的Web应用框架,它继承了Struts1的优点,并引入了更多现代框架的特性,如拦截器(Interceptor)机制,增强了Action类的功能。在S2SH整合中,Struts2主要负责请求分发和...

    泛型dao

    【泛型DAO】是一种在Java开发中常见的设计模式,它利用了Java泛型特性来提高代码的可重用性和类型安全性。在Java中,DAO(Data Access Object)模式是用来封装对数据库的操作,将业务逻辑与数据访问逻辑分离,使得...

    java 基于泛型与反射的通用 DAO

    综上所述,这个项目展示了如何利用Java的泛型和反射技术实现一个通用的DAO,使得数据库操作更加灵活和易于维护。泛型确保了类型安全,而反射则提供了运行时的动态行为。这种设计模式在实际开发中非常常见,尤其是在...

    泛型+泛型类+定义和使用+理解

    泛型是Java编程中的一种重要特性,它引入于JDK 5.0,极大地提高了代码的类型安全性和重用性。泛型允许我们在类、接口和方法中使用类型参数,这样在编译时就能检查类型,避免了运行时类型转换异常,同时也提供了更...

Global site tag (gtag.js) - Google Analytics