studentdao.java

来自「jsp例程」· Java 代码 · 共 99 行

JAVA
99
字号
package dao;

import hibernate.Student;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.web.struts.DelegatingActionProxy;
import org.springframework.web.struts.ContextLoaderPlugIn;
public class StudentDAO extends HibernateDaoSupport{
	private static Log log=LogFactory.getLog(StudentDAO.class);
	public List isUserValid(String  name,String password)
	{
		try{
		String[] studentlist=new String[2];
		studentlist[0]=name;
		studentlist[1]=password;
		List list=this.getHibernateTemplate().find("from Student stu where stu.Name=? and stu.Password=?",studentlist);
		return list;
		}catch(Exception e)
		{
			log.fatal(e);
			return null;
		}
	}
	public List getStudent()
	{
		List list=null;
		try{
		list=(List)this.getHibernateTemplate().find("from Student stu");
		}catch(Exception e)
		{
			log.error(e.getMessage());
			return null;
		}
		return list;
		
	}
	public boolean deleStudentByID(String id)
	{
		try{
		Student student=(Student) this.getHibernateTemplate().load(Student.class,id);
		this.getHibernateTemplate().delete(student);
		return true;
		}catch(Exception e)
		{
			log.error(e.getMessage());
			return false;
		}

	}
	
	public Student getStudentByID(String id)
	{
		try{
			Student student=(Student) this.getHibernateTemplate().load(Student.class,id);
			
			return student;
			}catch(Exception e)
			{
				log.error(e.getMessage());
				return null;
			}

	}
	
	public boolean updateStudent(Student student)
	{
		try{
			 this.getHibernateTemplate().update(student);
			 
			
			return true;
			}catch(Exception e)
			{
				log.error(e.getMessage());
				return false;
			}
		
	}
	public boolean saveStudent(Student student)
	{
		try{
			this.getHibernateTemplate().saveOrUpdate(student);
			
			return true;
		}catch(Exception e)
		{
			log.fatal(e);
			return false;
		}
		
		
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?