如何在spring中使用hibernate-成都快上网建站

如何在spring中使用hibernate

这期内容当中小编将会给大家带来有关如何在spring中使用hibernate,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

创新互联是一家专注于成都网站制作、网站建设和联通机房服务器托管的网络公司,有着丰富的建站经验和案例。

结构:

如何在spring中使用hibernate

Spring和Hibernate整合借助于HibernateTemplate

applicationContext.xml



 
  
    
  
  
  
    
  

  
    
    
      
        com/lc/pojo/Category.hbm.xml
      
    
    
      
        hibernate.dialect=org.hibernate.dialect.MySQLDialect
        hibernate.show_sql=true
        hbm2ddl.auto=update
        
    
    
    

  
    
    
    
    
    
 

测试:

ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
    CategoryDAO bean =(CategoryDAO) context.getBean("dao");

    DetachedCriteria criteria = DetachedCriteria.forClass(Category.class);

//    List list = bean.findByCriteria(criteria, 0, 5); //分页--取0-5个返回
//    System.out.println(list);

如何在spring中使用hibernate

 Category.hbm.xml




  
    
      
      
    
    
  

result:

如何在spring中使用hibernate

上述就是小编为大家分享的如何在spring中使用hibernate了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注创新互联行业资讯频道。


新闻标题:如何在spring中使用hibernate
URL地址:http://kswjz.com/article/joepoe.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流