欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

SpringDataJPA實(shí)現(xiàn)查詢分頁demo

SpringData JPA 的 PagingAndSortingRepository接口已經(jīng)提供了對分頁的支持,查詢的時候我們只需要傳入一個 org.springframework.data.domain.Pageable

創(chuàng)新互聯(lián)擁有一支富有激情的企業(yè)網(wǎng)站制作團(tuán)隊(duì),在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)深耕十載,專業(yè)且經(jīng)驗(yàn)豐富。十載網(wǎng)站優(yōu)化營銷經(jīng)驗(yàn),我們已為成百上千中小企業(yè)提供了成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)解決方案,按需定制制作,設(shè)計(jì)滿意,售后服務(wù)無憂。所有客戶皆提供一年免費(fèi)網(wǎng)站維護(hù)!

接口的實(shí)現(xiàn)類,指定PageNumber和pageSize即可

springData包中的 PageRequest類已經(jīng)實(shí)現(xiàn)了Pageable接口,我們可以直接使用下邊是部分代碼:

DAO:

package com.jiaoyiping.jdjy.sourcecode.dao;

import com.jiaoyiping.jdjy.sourcecode.bean.SourceCode;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * Created with IntelliJ IDEA.
 * User: 焦一平
 * Date: 14-11-20
 * Time: 下午11:18
 * To change this template use File | Settings | File Templates.
 */
public interface SourceCodeDao extends PagingAndSortingRepository<SourceCode, String> {

}

service:

package com.jiaoyiping.jdjy.sourcecode.service;

import com.jiaoyiping.jdjy.sourcecode.bean.SourceCode;
import com.jiaoyiping.jdjy.sourcecode.dao.SourceCodeDao;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import javax.transaction.Transactional;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 焦一平
 * Date: 14-11-20
 * Time: 下午11:24
 * To change this template use File | Settings | File Templates.
 */
public class SourceCodeService {
  @Autowired
  private SourceCodeDao sourceCodeDao;public Page<SourceCode> getSourceCode(int pageNumber,int pageSize){
    PageRequest request = this.buildPageRequest(pageNumber,pageSize);
    Page<SourceCode> sourceCodes= this.sourceCodeDao.findAll(request);
    return sourceCodes;
  }
  //構(gòu)建PageRequest
  private PageRequest buildPageRequest(int pageNumber, int pagzSize) {
    return new PageRequest(pageNumber - 1, pagzSize, null);
  }

}

controller:

package com.jiaoyiping.jdjy.sourcecode.controller;
import com.jiaoyiping.jdjy.sourcecode.Const;
import com.jiaoyiping.jdjy.sourcecode.bean.SourceCode;
import com.jiaoyiping.jdjy.sourcecode.service.SourceCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: 焦一平
 * Date: 14-11-20
 * Time: 下午11:22
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping(value = "/sourcecode")
public class SourceCodeController {
  @Autowired
  private SourceCodeService sourceCodeService;

  
  @RequestMapping(value = "list")
  public ModelAndView listSourceCode(HttpServletRequest request, HttpServletResponse response){
    String pageNumberStr=request.getParameter("pageNumber");
    if(pageNumberStr==null ||"".equals(pageNumberStr)){
      pageNumberStr="1";
    }
    int pageNumber = Integer.parseInt(pageNumberStr);
    int pageSize = Const.PAGE_SIZE;
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("/sourcecode/listSourceCode");
    Page<SourceCode> sourceCodes = this.sourceCodeService.getSourceCode(pageNumber, pageSize);
    modelAndView.addObject("sourceCodeList",sourceCodes.getContent());
    modelAndView.addObject("totalPageNumber",sourceCodes.getTotalElements());
    modelAndView.addObject("pageSize",pageSize);
    return modelAndView;

  }

}

 前端分頁:

前端分頁組件我們使用bootstrap提供的分頁組件:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%--
 Created by IntelliJ IDEA.
 User: 焦一平
 Date: 2014/12/27
 Time: 9:57
 To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
 String basePath = request.getContextPath();
 String MethodURL=basePath+"/sourcecode/list.action?pageNumber=";
%>
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8"/>
 <title>源代碼列表</title>

 <link href="<%=basePath%>/resources/assets/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet"/>
 <script type="text/javascript" src="<%=basePath%>/resources/js/jquery/jquery.js"></script>


 <script type="text/javascript">
  $(document).ready(function(){
   var totalNumber = Number(${totalPageNumber});
   var pageSize = Number(${pageSize});
   var pageCount = totalNumber/pageSize;
   var html = "";
   for(var i = 0;i<pageCount;i++){
    var link_Url = "<li><a href=\"<%=MethodURL%>"+(i+1)+"\">"+(i+1)+"</a></li>";
    html += link_Url;
   }
   var fenyeDiv = document.getElementById("link");
   fenyeDiv.innerHTML=html;
  });
 </script>
</head>
<body>
<a href="#" rel="external nofollow" class="list-group-item active">
 源代碼列表
</a>
  <c:forEach items="${sourceCodeList}" var="sourceCode">
   <a href="<%=request.getContextPath()%>/sourcecode/detail.action?id=<c:out value=" rel="external nofollow" ${sourceCode.id}" />" class="list-group-item"><c:out value="${sourceCode.title}" /></a>
  </c:forEach>
<!-- 列表分頁的DIV,由JS動態(tài)填充內(nèi)容-->
<ul class="pagination pagination-lg" id="link">

</ul><br>

</body>
</html> 

最終結(jié)果如下:

SpringData JPA實(shí)現(xiàn)查詢分頁demo

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

文章名稱:SpringDataJPA實(shí)現(xiàn)查詢分頁demo
本文來源:http://www.aaarwkj.com/article6/gjcdog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、服務(wù)器托管用戶體驗(yàn)、網(wǎng)站導(dǎo)航品牌網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
92午夜福利精品视频| 午夜福利不卡片在线观看| 国产三级精品三级在线播放| 国产,欧美,日韩,日日骚| 日韩美少妇大胆一区二区| 精品人妻一区二区三区mp4| 丰满人妻被黑人猛烈进入 | 亚洲综合一区二区精品久久| 尤物欧美精品一区二区三区| 日本成人在线播放网站| 亚洲av天堂在线观看| 久久九特黄的免费大片| 中高龄夫妇五十路六十路| 久久99热这里只频精品| 欧美香蕉一区二区视频| 国产真实乱偷精品视频免| 国产视频一区二区三区网| 伊人蕉影院久亚洲高清| 91在线播放欧美国产视频| 日本精品中文字幕人妻| 国产精品黑丝美女91| 日本一级黄色影视大全| 国产一区二区精品日韩| 日本高清不卡在线观看| 蜜臀视频网站在线观看| 国产精品一区二区三区 在线 | 国产激情福利一区二区| 成人中文字幕日韩电影| 91老熟女露脸大合集| 亚洲国产区男人的天堂| 国产亚洲一区二区三区乱码| 色偷偷亚洲精品一区二区| 婷婷国产综合一区二区三区| 97在线公开免费视频| 中文字幕成人在线电影 | 伊人青草免费在线视频| 加勒比人妻一区二区三区| 精品传媒国产在线观看| 中文字幕在线不卡精品视频| 亚洲av香蕉一区二区| 男女啪啪国产精品视频|