This article is based on the previous blog post, the Hibernatetemplate class is invoked by inheriting Hibernatedaosupport, as long as the Userdaoimpl.java is changed to inherit the Hibernatedaosupport class. There are spring-dao.xml files added to the Hibernatedaosupport configuration bean, the specific implementation of the source code as follows:
Userdaoimpl.java
Package www.csdn.spring.hibernate.dao.copy;
Import java.util.List;
Import Org.springframework.orm.hibernate3.HibernateTemplate;
Import Org.springframework.orm.hibernate3.support.HibernateDaoSupport;
Import Www.csdn.spring.hibernate.domain.Users; public class Usersdaoimpl extends Hibernatedaosupport implements usersdao{@Override public void Save (Users entity)
{gethibernatetemplate (). Save (entity); @Override public list<users> getobjects (Class clazz) {return Gethibernatetempl
Ate (). Find ("from" +clazz.getname ()); @Override public void Deletebyid (Class clazz,integer id) {//gethibernatetemplate (). Delete (hi
Bernatetemplate.get (Clazz.getname (), id));
Gethibernatetemplate (). Bulkupdate ("Delete from" +clazz.getname () + "where id=" +id); @Override public void Update (Users entity) {GethiBernatetemplate (). Update (entity); }
}
Spring-dao.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns=
"Http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http:// Www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd ">
<bean id= "Hibernatedaosupport" class= "Org.springframework.orm.hibernate3.support.HibernateDaoSupport"
abstract= "true" >
<property name= "hibernatetemplate" ref= "hibernatetemplate" >
</property >
</bean>
<bean id= "Usersdaoimpl" class= "Www.csdn.spring.hibernate.dao.copy.UsersDaoImpl"
parent= "Hibernatedaosupport" >
</bean>
</beans>