日期:2014-05-18 浏览次数:20840 次
public interface IBaseDAO<T, ID extends Serializable> {
public T findById(ID id);
public T findById(Class c, ID id);
}
public class BaseDAO<T, ID extends Serializable> extends HibernateDaoSupport implements IBaseDAO<T, ID> {
private Class<T> persistentClass;
@SuppressWarnings("unchecked")
public BaseDAO(Class clazz) {
this.persistentClass = clazz;
}
public T findById(ID id){
return null;
}
public T findById(Class c, ID id){
System.out.println("进来了");
return null;
}
//getter && setter
public Class<T> getPersistentClass() {
return persistentClass;
}
public void setPersistentClass(Class<T> persistentClass) {
this.persistentClass = persistentClass;
}
}
public interface IBaseUserDAO {
public void findById(String id);
}
@SuppressWarnings("unchecked")
public class BaseUserDAO extends BaseDAO implements IBaseUserDAO {
private BaseDAO baseDao;
public BaseUserDAO(String clazz) throws ClassNotFoundException {
// Class.forName("BaseDAOTest");
// System.out.println(clazz);
super(Class.forName("cn.aozer.armsweb.entity.Users"));
}
public void findById(String id) {
System.out.println("User DAO");
Users u = (Users)this.findById(Users.class,id);
System.out.println(u.getUsername());
System.out.println(u.getPassword());
}
public BaseDAO getBaseDao() {
return baseDao;
}
public void setBaseDao(BaseDAO baseDao) {
this.baseDao = baseDao;
}
}
<bean id="baseDao" class="test.BaseDAO" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="baseUser" class="test.BaseDAOTestForUserDAO" parent="baseDao">