javaweb项目库存管理系统struts+spring+hibernate-java课程设计毕业设计
立即下载
资源介绍:
本资源为“JavaWeb库存管理系统”项目源码,采用Struts+Spring+Hibernate(SSH)框架进行开发,旨在为在校大学生的Java课程设计和毕业设计提供宝贵的学习参考。系统功能涵盖进货管理、销售管理、库存管理、用户登录等模块,代码结构清晰、便于学习和理解。项目使用JSP技术实现前端展示,利用Spring框架进行依赖注入,Hibernate处理数据持久化,确保系统稳定高效。该源码非常适合对SSH框架及库存管理系统感兴趣的Java学习者,为提升Java开发技能、掌握企业级应用开发提供了优质的参考资料。
package com.cxstock.dao.impl;
import java.io.Serializable;
import java.sql.Connection;
import java.util.Collection;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.cxstock.dao.BaseDAO;
/** 统一数据访问接口实现 */
@SuppressWarnings("unchecked")
public class BaseDAOImpl extends HibernateDaoSupport implements BaseDAO {
/** 保存或更新指定的持久化对象 */
public void save(Object obj) {
getHibernateTemplate().save(obj);
}
/** 保存或更新指定的持久化对象 */
public void saveOrUpdate(Object obj) {
getHibernateTemplate().saveOrUpdate(obj);
}
/** 删除指定ID的持久化对象 */
public void deleteById(Class clazz, Serializable id) {
getHibernateTemplate().delete(getHibernateTemplate().load(clazz, id));
}
/** 删除指定ID的持久化对象 */
public void delete(Object obj) {
getHibernateTemplate().delete(obj);
}
/** 加载指定ID的持久化对象 */
public Object loadById(Class clazz, Serializable id) {
return getHibernateTemplate().get(clazz, id);
}
/**加载满足条件的持久化对象*/
public Object loadObject(String hql) {
final String hql1 = hql;
Object obj = null;
List list = getHibernateTemplate().find(hql1);
if(list.size()>0)obj=list.get(0);
return obj;
}
/** 查询指定类的满足条件的持久化对象 */
public List findByHql(String hql) {
try{
final String hql1 = hql;
return getHibernateTemplate().find(hql1);
}
catch (Exception e) {
e.printStackTrace();
}return null;
}
/** 装载指定类的查询结果 */
public List findInProperty(String clazz, String propertyName, String value) {
String hql = "from "+clazz+" as model where model." + propertyName + " in (" + value + ")";
return getHibernateTemplate().find(hql);
}
/** 装载指定类的查询结果 */
public List findLikeProperty(String clazz, String propertyName, String value) {
String hql = "from "+clazz+" as model where model." + propertyName + " like ?";
return getHibernateTemplate().find(hql, value);
}
/** 装载指定类的查询结果 */
public List findByProperty(String clazz, String propertyName, Object value) {
String hql = "from "+clazz+" as model where model." + propertyName + "= ?";
return getHibernateTemplate().find(hql, value);
}
/** 装载指定类的查询结果 */
public List findByProperty(String clazz, String[] propertyName, Object[] value) {
String hsql = "from "+clazz+" as model where 1=1";
for (int i = 0; i < propertyName.length; i++) {
hsql += " and model." + propertyName[i] + "= ?";
}
return getHibernateTemplate().find(hsql, value);
}
/** 装载指定类的所有持久化对象 */
public List listAll(String clazz) {
return getHibernateTemplate().find("from "+clazz);
}
/** 条件更新数据 */
public int update(String hql) {
final String hql1 = hql;
return ((Integer)getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery(hql1);
return query.executeUpdate();
}
})).intValue();
}
/** 统计指定类的所有持久化对象 */
public int countAll(String clazz) {
final String hql = "select count(*) from "+clazz;
Long count = (Long)getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery(hql);
query.setMaxResults(1);
return query.uniqueResult();
}
});
return count.intValue();
}
/** 统计指定类的查询结果 */
public int countQuery(String hql) {
final String counthql = hql;
Long count = (Long)getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery(counthql);
query.setMaxResults(1);
return query.uniqueResult();
}
});
return count.intValue();
}
/** 分页装载指定类的查询结果 */
public List findInProperty(String clazz, String propertyName, String value, int start, int limit) {
String hql = "from "+clazz+" as model where model." + propertyName + " in (" + value + ")";
return this.findByHql(hql, start, limit);
}
/** 分页装载指定类的查询结果 */
public List findLikeProperty(String clazz, String propertyName, String value, int start, int limit) {
String hql = "from "+clazz+" as model where model." + propertyName + " like '"+value+"%'";
return this.findByHql(hql, start, limit);
}
/** 分页装载指定类的查询结果 */
public List findByProperty(String clazz, String propertyName, String value, int start, int limit) {
String hql = "from "+clazz+" as model where model." + propertyName + "= '"+value+"'";
return this.findByHql(hql, start, limit);
}
/** 分页装载指定类的查询结果 */
public List findByProperty(String clazz, String[] propertyName, Object[] value, int start, int limit) {
String hql = "from "+clazz+" as model where 1=1";
for (int i = 0; i < propertyName.length; i++) {
hql += " and model." + propertyName[i] + "= '"+value[i]+"'";
}
return this.findByHql(hql, start, limit);
}
/** 分页装载指定类的所有持久化对象 */
public List listAll(String clazz, int start, int limit) {
final int pStart = start;
final int pLimit = limit;
final String hql = "from "+clazz;
List list = getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery(hql);
query.setMaxResults(pLimit);
query.setFirstResult(pStart);
List result = query.list();
if (!Hibernate.isInitialized(result))Hibernate.initialize(result);
return result;
}
});
return list;
}
/** 分页查询指定类的满足条件的持久化对象 */
public List findByHql(String hql, int start, int limit) {
final int pStart = start;
final int pLimit = limit;
final String hql1 = hql;
return getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{
Query query = session.createQuery(hql1);
query.setMaxResults(pLimit);
query.setFirstResult(pStart);
List result = query.list();
if (!Hibernate.isInitialized(result))Hibernate.initialize(result);
return result;
}
});
}
/** 从连接池中取得一个JDBC连接 */
@SuppressWarnings("deprecation")
public Connection getConnection() {
return getHibernateTemplate().getSessionFactory().getCurrentSession().connection();
}
/** 批量保存、修改 */
public void saveOrUpdateAll(Collection collection) {
getHibernateTemplate().saveOrUpdateAll(collection);
}
/** 调用存储过程 */
public void callProcedure(String call) {
SQLQuery query = this.getSession().createSQLQuery(call);
query.executeUpdate();
}
}
资源文件列表:
库存管理系统.zip 大约有1822个文件