📄 empdaoimpl.java
字号:
package com.tatang.dao.impl;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.tatang.dao.IEmpDao;
import com.tatang.po.TEmployee;
import com.tatang.util.HibernateSessionFactory;
public class EmpDaoImpl implements IEmpDao{
public List<TEmployee> empList(Integer id) {
Session session = null;
Transaction tx = null;
Query q = null;
String sql="from TEmployee";
try{
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
q = session.createQuery(sql);
q.setInteger(0,id);
List<TEmployee> list = new ArrayList();
list = q.list();
tx.commit();
return list;
}catch(HibernateException e){
tx.rollback();
e.printStackTrace();
return null;
}finally{
HibernateSessionFactory.closeSession();
}
}
public List<TEmployee> empList() {
Session session = null;
Transaction tx = null;
Query q = null;
String sql="from TEmployee";
try{
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
q = session.createQuery(sql);
List<TEmployee> list = new ArrayList();
list = q.list();
tx.commit();
return list;
}catch(HibernateException e){
tx.rollback();
e.printStackTrace();
return null;
}finally{
HibernateSessionFactory.closeSession();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -