Introduction to Spring ((a) spring and Hibernate integration complete the add-and-check operation

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.