日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用Hibernate代碼實(shí)例

本文主要講述了在使用Hibernate時(shí),如何實(shí)現(xiàn)group by and sum and count。希望本文能教會(huì)你更多東西。

專注于為中小企業(yè)提供成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)卡若免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近1000家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

Hibernate是JDBC的升級版,專用連接數(shù)據(jù)庫。它比JDBC簡單使用,不需要輸入很多的連接數(shù)據(jù)庫代碼。提取數(shù)據(jù)庫數(shù)據(jù)也不用循環(huán)提取。使用時(shí)的方法為:

1.新建一個(gè)Java普通項(xiàng)目

2.創(chuàng)建user library 加入三個(gè)地方的jar包:兩個(gè)hibernate 一個(gè)MYSQL驅(qū)動(dòng)

3.創(chuàng)建hibernate配置文件,hibernate.cfg.xml

4.建立實(shí)體類user

5.在hibernate文件中尋找eg至底部找出user.hbm.xml映射文件,copy到映射文件所在文件中

6.將映射文件user.hbm.xml部分加入到hibernate.cfg.xml中

7.創(chuàng)建數(shù)據(jù)庫,再利用hibernate將實(shí)體映射導(dǎo)入到數(shù)據(jù)庫中

下面是具體實(shí)現(xiàn)的代碼:

 
 
 
  1. //使用hibernate,實(shí)現(xiàn)group by and sum and count  
  2.   Session sess = this.getSession(false);  
  3.   List list = null;  
  4.   if (sess != null) {  
  5.    Criteria cri = sess.createCriteria(getModelClass());  
  6.    cri.add(Expression.allEq(props));  
  7.    // always count id  
  8.    ProjectionList projList = Projections.projectionList();  
  9.    projList.add(Projections.sum(sum));  
  10.    projList.add(Projections.groupProperty(group1));  
  11.    projList.add(Projections.groupProperty(group2));  
  12.    projList.add(Projections.count(count));  
  13.    cri.setProjection(projList);  
  14.    list = cri.list();  
  15.   }  
  16.   listlist = list == null ? new ArrayList() : list;  
  17.   return list;  
  18.  
  19.   //使用hibernate,實(shí)現(xiàn)group by and sum and count  
  20.   List listByGroupSum = dao.getListByGroupSumCP(props);  
  21.   Iterator iter = listByGroupSum.iterator();  
  22.   if (!iter.hasNext()) {  
  23.    System.out.println("No objects to display.");  
  24.  
  25.   }  
  26.   while (iter.hasNext()) {  
  27.    System.out.println("New object");  
  28.    Object[] obj = (Object[]) iter.next();  
  29.    for (int i = 0; i < obj.length; i++) {  
  30.     System.out.println(obj[i]);  
  31.    }  
  32.  
  33.   }   
  34.  

當(dāng)前題目:使用Hibernate代碼實(shí)例
鏈接分享:http://www.5511xx.com/article/dphpggp.html