studentdao.java
来自「Hibernate开发及整合应用大全 蔡雪焘编著 本书用典型的示例剖析Hiber」· Java 代码 · 共 59 行
JAVA
59 行
package dao;
import java.util.ArrayList;
import java.util.List;
import model.Student;
import model.StudentVO;
import org.apache.commons.beanutils.BeanUtils;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import persistence.HibernateUtil;
public class StudentDAO extends BaseDAO {
public static List getAllStu()
{
List list=null;
List temp=new ArrayList();
Transaction tx = null;
try {
Session session = HibernateUtil.currentSession();
tx = session.beginTransaction();
Query q = session.createQuery("from Student");
temp=q.list();
list=new ArrayList(temp.size());
for(int i=0;i<temp.size();i++)
{
Student stu_po=(Student) temp.get(i);
StudentVO stu_vo=new StudentVO();
BeanUtils.copyProperties(stu_vo, stu_po);
list.add(stu_vo);
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
try {
tx.rollback();
} catch (HibernateException e1) {
e1.printStackTrace();
}
} finally {
try {
HibernateUtil.closeSession();
} catch (HibernateException e1) {
e1.printStackTrace();
}
}
return list;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?