国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - SpringData JPA實現查詢分頁demo

SpringData JPA實現查詢分頁demo

2020-08-21 12:03夢中彩虹 Java教程

本篇文章主要介紹了SpringData JPA實現查詢分頁demo,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

接口的實現類,指定PageNumber和pageSize即可

springData包中的 PageRequest類已經實現了Pageable接口,我們可以直接使用下邊是部分代碼:

DAO:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
  }
  //構建PageRequest
  private PageRequest buildPageRequest(int pageNumber, int pagzSize) {
    return new PageRequest(pageNumber - 1, pagzSize, null);
  }
 
}

controller:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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提供的分頁組件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<%@ 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動態填充內容-->
<ul class="pagination pagination-lg" id="link">
 
</ul><br>
 
</body>
</html>

最終結果如下:

SpringData JPA實現查詢分頁demo

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.cnblogs.com/jiaoyiping/p/4189114.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: t66y最新地址一地址二69 | 成人影院在线观看 | 亚洲一区国产视频 | 亚洲狠狠爱| 国产乱码精品一区二区三区忘忧草 | 国产一区二区视频在线 | 黄在线看v | 黄色在线免费看 | 狠狠躁夜夜躁人人爽天天天天97 | 免费一级毛片 | 国产激情一区二区三区 | 日韩国产免费观看 | 精品一区二区三 | 欧美色影院 | 欧美中文字幕在线 | 精品国产91亚洲一区二区三区www | 午夜资源 | 国产精品国产三级国产aⅴ中文 | 国内自拍网站 | av亚洲在线 | 另类国产ts人妖高潮系列视频 | 亚洲综合色自拍一区 | 国产毛片区 | 久久精品亚洲成在人线av网址 | 日韩成人在线视频 | 久久精品国产一区二区电影 | 日韩av免费在线观看 | 精品国产成人 | 精品美女久久久 | 久久中文字幕一区二区三区 | 四虎影院网| 国产中文视频 | 亚洲国产综合在线 | 日韩在线播放一区 | 国产亚洲网站 | 亚洲成人精品一区 | 天天玩天天操天天射 | 亚洲国产精品激情在线观看 | 99看| www.久久.com| 涩涩一区 |