真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

java中對(duì)list分頁(yè)并顯示數(shù)據(jù)到頁(yè)面實(shí)例代碼

有時(shí)候需要根據(jù)條件查詢(xún)得出的數(shù)據(jù)較多,需要分頁(yè)顯示到頁(yè)面上。這時(shí)點(diǎn)擊下一頁(yè)就不方便每次帶查詢(xún)條件在數(shù)據(jù)庫(kù)中分頁(yè)??梢栽趌ist中進(jìn)行分頁(yè)。

創(chuàng)新互聯(lián)主營(yíng)石河子網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件定制開(kāi)發(fā),石河子h5小程序制作搭建,石河子網(wǎng)站營(yíng)銷(xiāo)推廣歡迎石河子等地區(qū)企業(yè)咨詢(xún)

page的model類(lèi):

public class Page { 
  private Integer currentPage;//當(dāng)前頁(yè) 
  private int pageSize;//每頁(yè)顯示記錄條數(shù) 
  private int totalPage;//總頁(yè)數(shù) 
  private List<?> dataList;//每頁(yè)顯示的數(shù)據(jù) 
  private int star;//開(kāi)始數(shù)據(jù) 
 
  public Integer getCurrentPage() { 
    return currentPage; 
  } 
  public void setCurrentPage(Integer currentPage) { 
    this.currentPage = currentPage; 
  } 
  public int getPageSize() { 
    return pageSize; 
  } 
  public void setPageSize(int pageSize) { 
    this.pageSize = pageSize; 
  } 
  public int getTotalPage() { 
    return totalPage; 
  } 
  public void setTotalPage(int totalPage) { 
    this.totalPage = totalPage; 
  } 
  public List<?> getDataList() { 
    return dataList; 
  } 
  public void setDataList(List<?> dataList) { 
    this.dataList = dataList; 
  } 
  public int getStar() { 
    return star; 
  } 
  public void setStar(int star) { 
    this.star = star; 
  } 
} 

控制層:

@RequestMapping("fenye.do") 
  public String fen(Page page,HttpServletRequest request){ 
 
    try { 
      //查詢(xún)出的list數(shù)據(jù) 
      List showdata=loginService.selectyichall(); 
      //剛開(kāi)始的頁(yè)面為第一頁(yè) 
      if (page.getCurrentPage() == null){ 
        page.setCurrentPage(1); 
      } else { 
        page.setCurrentPage(page.getCurrentPage()); 
      } 
      //設(shè)置每頁(yè)數(shù)據(jù)為十條 
      page.setPageSize(10); 
      //每頁(yè)的開(kāi)始數(shù) 
      page.setStar((page.getCurrentPage() - 1) * page.getPageSize()); 
      //list的大小 
      int count = showdata.size(); 
      //設(shè)置總頁(yè)數(shù) 
      page.setTotalPage(count % 10 == 0 ? count / 10 : count / 10 + 1); 
      //對(duì)list進(jìn)行截取 
      page.setDataList(showdata.subList(page.getStar(),count-page.getStar()>page.getPageSize()?page.getStar()+page.getPageSize():count)); 
      //設(shè)置作用域 
      request.setAttribute("paging", page);         
      return "add/show.jsp"; 
 
    } catch (Exception e) { 
      // TODO Auto-generated catch block    
      e.printStackTrace(); 
      return "mistake.jsp"; 
    } 
  } 

jsp頁(yè)面:

 
 
 
${upl.name1 } ${upl.name2 } ${upl.name3 }
當(dāng)前第 ${paging.currentPage } 頁(yè)/共 ${paging.totalPage} 頁(yè) 首頁(yè) 上一頁(yè) 下一頁(yè) 末頁(yè) 首頁(yè) 上一頁(yè) 首頁(yè) 上一頁(yè) 下一頁(yè) 末頁(yè) 共 ${paging.total} 條
StringBuilder sb = new StringBuilder(); 
sb.append("SELECT distinct(m.time) "); 
sb.append(" from tbl_monitor m left join tbl_variable v on m.variable = v.id "); 
sb.append(" left join tbl_variable_group g on v.variable_group = g.id "); 
       
sb.append(" where v.active = true and g.active=true "); 
//sb.append(" AND m.variable in " + variableIds); 
sb.append(" AND exists ( select vtemp.id from tbl_variable vtemp where vtemp.selected=true and vtemp.id=m.variable)"); 
sb.append(" AND m.time between " + beginTime + " AND " + endTime ); 
sb.append(" order by m.time asc"); 
Query query = em.createNativeQuery(sb.toString()); 
//滿(mǎn)足搜索條件的所有的時(shí)間的條數(shù) 
int total = query.getResultList().size(); 
tableView.setTotal(total); 
tableView.setTotalPage(total % page.getPageSize() == 0 ? total / page.getPageSize() : (total / page.getPageSize()) + 1); 
query.setFirstResult(from); 
query.setMaxResults(offset); 
timeList = query.getResultList(); 

總結(jié)

以上就是本文關(guān)于java中對(duì)list分頁(yè)并顯示數(shù)據(jù)到頁(yè)面實(shí)例代碼的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專(zhuān)題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!


當(dāng)前文章:java中對(duì)list分頁(yè)并顯示數(shù)據(jù)到頁(yè)面實(shí)例代碼
網(wǎng)站地址:http://weahome.cn/article/pgdipj.html

其他資訊

在線咨詢(xún)

微信咨詢(xún)

電話咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部