哎。。弄出来了
==============================================
package com.cls.dao;
public interface BaseDao<T,S> {
public void save(T entity);
public void deleteById(S PK);
public void delete(T entity);
public void update(T entity);
public T findById(S PK);
}
===============================================
package com.cls.daoimpl;
import
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import sun.security.action.GetBooleanAction;
import com.cls.dao.BaseDao;
public class BaseDaoImpl<T, S extends Serializable> implements BaseDao<T, S> {
protected Class entityClass;
private SessionFactory sessionFactory;
ApplicationContext apc = new FileSystemXmlApplicationContext(
"/WEB-INF/classes/applicationContext.xml");
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = (SessionFactory) apc.getBean("sessionFactory");
}
public void delete(T entity) {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.delete(entity);
session.close();
();
}
public void deleteById(S PK) {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
T t = (T) session.get(this.entityClass, PK);
session.delete(t);
();
}
public T findById(S PK) {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
T t = (T) session.get(this.entityClass, PK);
return t;
}
public void save(T entity) {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(entity);
();
}
public void update(T entity) {
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(entity);
();
}
}
====================================================