我就很纳闷不知道为什么会出错,请大家看一眼。
IBaseDAO接口。
public interface IBaseDAO<T, ID extends Serializable> {
public T findById(ID id);
public T findById(Class c, ID id);
}
BaseDAO实现类
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;
}
}
UserDAO接口
public interface IBaseUserDAO {
public void findById(String id);
}
UserDAO实现。
@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;
}
}
最后是spring、配置文件
<bean id="baseDao" class="test.BaseDAO" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="baseUser" class="test.BaseDAOTestForUserDAO" parent="baseDao">