2016-08-13 40 views
0

我使用Play 2.2.6。我想獲得'getTotalPageCount'RawSql,但是 我總是得到一個頁面記錄。 下面是代碼:播放幀RawSql我如何getTotalPage

String sql = "select " 
      + "a.id as id ," 
      + "b.name as computerType ," 
      + "a.buy_time as buyTime ," 
      + "a.user_name as userName, " 
      + "a.if_use as ifUse from computer a left join computer_type b on a.computer_type = b.code where 1=1 "; 

    if(StringUtil.StringNoEmpty(vo.userName)){ 
     sql += " and a.user_name like '%"+vo.userName+"%'"; 
    } 

    if(StringUtil.StringNoEmpty(vo.computerType)){ 
     sql += " and a.computer_type = '"+vo.computerType+"'"; 
    } 
    if(null!=vo.startTime){   
     String startTime = DateUtil.formate.format(vo.startTime); 
     sql += " and a.buy_time >= '"+startTime+"'"; 
    } 

    if(null!=vo.endTime){ 
     String endTime = DateUtil.formate.format(vo.endTime); 
     sql += " and a.buy_time <= '"+endTime+"'"; 
    } 

    if(StringUtil.StringNoEmpty(vo.ifUse)){ 
     if("on".equals(vo.ifUse)){ 
      sql += " and a.if_use ='1' "; 
     }else if("off".equals(vo.ifUse)){ 
      sql += " and a.if_use = '0'"; 
     } 
    } 

    RawSql rawSql = RawSqlBuilder.parse(sql).create(); 

    Query<ResultComputer> query = Ebean.find(ResultComputer.class).order("id"); 
    query.setRawSql(rawSql); 

    Page<ResultComputer> page = query.findPagingList(10).setFetchAhead(false).getPage(0); 
    Logger.debug(page.getTotalPageCount()+""); // result 1. 

但我的數據庫中有1000條記錄。我認爲「page.getTotalPageCount()」應該是100頁的記錄。我的錯誤在哪裏?

回答

0
public int getTotalPageCount(); 

返回你給getPage(0) pages.Since的總數,則返回1。[getPage(0) -return對於給定的頁的位置的頁(從0開始)。如果您想要總頁數:執行getTotalPageCount();pagingList