📄 studentdao.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -