最代码-JSON的gravatar头像
最代码-JSON 2014-12-05 00:20:04

Struts2+Hibernate开发学生成绩后台管理系统

这个项目是利用Struts2+Hibernate实现的一个简单的学生以及学生成绩管理系统,基本上都是CRUD,以及登陆功能。拿来练练手确实是一个相当不错的Demo实例。数据库采用的MySQL数据库,为了方便牛友,提供了相应的数据库,其实有hibernate的话可以反向生成数据库的。登陆名:081101,口令:123

Struts2+Hibernate开发学生成绩后台管理系统Struts2+Hibernate开发学生成绩后台管理系统

 

 

package chao.daoimp;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import chao.dao.CjDao;
import chao.model.Cjb;
import chao.util.HibernateSessionFactory;

public class CjDaoImp implements CjDao {
	
    public Cjb getXsCj(String xh,String kch)
    {	
    	Cjb cj=null;
    	Session session = null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Query query=session.createQuery("from Cjb where id.xsb.xh='"+xh+"'"+"and id.kcb.kch='"+kch+"'");
    		cj=(Cjb) query.uniqueResult();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
		return cj;
    }
    //根据学号查出学生的姓名及所有课程的课程号、课程名、所获成绩和学分

    public List getKcCjList(String kch)
    {
    	List list=null;
    	Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Query query=session.createQuery("from Cjb where id.kcb.kch='"+kch+"'");
    		list=query.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
		return list;
    }

    public List getXsCjList(String xh)
    {
    	List list=null;
    	Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Query query=session.createQuery("from Cjb where id.xsb.xh='"+xh+"'");
    		list=query.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
		return list;
    }
    //查出所有成绩的学生的学号、姓名、获得学分及对应课程号和课程名
    public List findAllCj(int pageNow, int pageSize) 
    {
    	List list=null;
    	Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Query query=session.createQuery("from Cjb");
    		int firstResult = (pageNow - 1) * pageSize;
			query.setFirstResult(firstResult);
			query.setMaxResults(pageSize);
    		list=query.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
		return list;
	}
    public int findCjSize() {
    	int size=0;
    	Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Query query=session.createQuery("from Cjb");
    		List list=query.list();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			
		}
		finally{
			session.close();
		}
		return size;
	}
	public void deleteCj(String xh,String kch)
    {
		Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Transaction ts = session.beginTransaction();
    		Query query=session.createQuery("from Cjb where id.xsb.xh='"+xh+"'"+"and id.kcb.kch='"+kch+"'");
    		Cjb cj=(Cjb) query.uniqueResult();
    		session.delete(cj);
    		ts.commit();

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
    }
	//删除所有符合课程号的学生成绩
	public void deleteOneKcInfo(String kch)
	{
		Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Transaction ts = session.beginTransaction();
    		session.delete(getKcCjList(kch));
    		ts.commit();

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
	}
	//删除所有符合学号的学生成绩
	public void deleteOneXsCj(String xh)
	{
		Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Transaction ts = session.beginTransaction();
    		session.delete(getXsCjList(xh));
    		ts.commit();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
	}
	public void save(Cjb cj)
	{
		Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Transaction ts = session.beginTransaction();
    		session.save(cj);
    		ts.commit();

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
	}
	public void update(Cjb cj)
	{
		Session session=null;
    	try {
    		session=HibernateSessionFactory.getSession();
    		Transaction ts = session.beginTransaction();
    		session.update(cj);
    		ts.commit();

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		finally{
			session.close();
		}
	}
}

打赏

文件名:student.zip,文件大小:10508.116K 下载
最代码最近下载分享源代码列表最近下载
571818771  LV3 2024年12月16日
fesfefe  LV13 2023年9月26日
15116483404  LV2 2021年12月13日
云脏111111  LV2 2021年5月15日
tx1121  LV14 2021年5月6日
admin_z  LV22 2021年5月1日
and123456  LV11 2021年4月10日
pierce  LV12 2021年3月11日
862960632  LV14 2020年7月7日
最代码最近浏览分享源代码列表最近浏览
571818771  LV3 2024年12月16日
颜菜菜  LV2 2024年6月19日
WBelong  LV8 2023年12月25日
卢本伟不开挂  LV4 2023年10月22日
fesfefe  LV13 2023年9月26日
wbx666  LV1 2023年9月18日
zhanglm119  LV3 2023年8月30日
sandihha  LV9 2023年4月24日
upup996  LV6 2022年12月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友