1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

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

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      SpringDataJPA實(shí)現(xiàn)查詢分頁(yè)demo

      SpringData JPA 的 PagingAndSortingRepository接口已經(jīng)提供了對(duì)分頁(yè)的支持,查詢的時(shí)候我們只需要傳入一個(gè) 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)化營(yíng)銷經(jīng)驗(yàn),我們已為成百上千中小企業(yè)提供了成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)解決方案,按需定制制作,設(shè)計(jì)滿意,售后服務(wù)無(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 {
      
      }
      

      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 getSourceCode(int pageNumber,int pageSize){
          PageRequest request = this.buildPageRequest(pageNumber,pageSize);
          Page 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 sourceCodes = this.sourceCodeService.getSourceCode(pageNumber, pageSize);
          modelAndView.addObject("sourceCodeList",sourceCodes.getContent());
          modelAndView.addObject("totalPageNumber",sourceCodes.getTotalElements());
          modelAndView.addObject("pageSize",pageSize);
          return modelAndView;
      
        }
      
      }
      
      

       前端分頁(yè):

      前端分頁(yè)組件我們使用bootstrap提供的分頁(yè)組件:

      <%@ 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=";
      %>
      
      
      
       
       源代碼列表
      
       
       
      
      
       
      
      
      
       源代碼列表
      
        
         " class="list-group-item">
        
      
      

      最終結(jié)果如下:

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

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


      分享文章:SpringDataJPA實(shí)現(xiàn)查詢分頁(yè)demo
      網(wǎng)站鏈接:http://www.ef60e0e.cn/article/gjcdog.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        高密市| 拜城县| 富阳市| 赣州市| 紫云| 舟山市| 凉山| 南汇区| 香格里拉县| 会理县| 太原市| 普洱| 沙洋县| 凤山县| 岳西县| 清徐县| 宁阳县| 吕梁市| 永靖县| 宜兰市| 伊宁市| 民县| 安泽县| 连云港市| 同仁县| 遵义县| 仙居县| 和田市| 郁南县| 贡觉县| 无棣县| 西乡县| 靖远县| 龙里县| 金川县| 固安县| 长兴县| 许昌市| 宽城| 隆子县| 罗平县|