1. 程式人生 > >基於springBoot+DataTables外掛的分頁實現

基於springBoot+DataTables外掛的分頁實現

這個外掛我感覺挺好用,配置也簡單,自帶條件物件,下面我就以我的專案程式碼來說明:

首先重要的兩個依賴:

<script  src="../../hplus/plugins/hjk/plugins/DataTables/js/jquery.dataTables.js"></script>
<link href="../../hplus/plugins/hjk/plugins/DataTables/css/data-table.css" rel="stylesheet">

接下來是前臺程式碼:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
> <!-- Mirrored from www.zi-han.net/theme/hplus/weixinportal.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:19:58 GMT --> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>微信選單
</title> <meta name="keywords" content="H+後臺主題,後臺bootstrap框架,會員中心主題,後臺HTML,響應式後臺"> <meta name="description" content="H+是一個完全響應式,基於Bootstrap3最新版本開發的扁平化主題,她採用了主流的左右兩欄式佈局,使用了Html5+CSS3等現代技術"> <link rel="shortcut icon" href="../favicon.ico"> <link href="../../hplus/css/bootstrap.min14ed.css?v=3.0.3"
rel="stylesheet"> <link href="../../hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet"> <link href="../../hplus/css/animate.min.css" rel="stylesheet"> <link href="../../hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet"> <link href="../../hplus/plugins/hjk/plugins/jquery-confirm/jquery-confirm.min.css" rel="stylesheet"/> <link href="../../hplus/plugins/hjk/css/bootstrap-treeview.css" rel="stylesheet"> <link href="../../hplus/plugins/hjk/plugins/gritter/css/jquery.gritter.css" rel="stylesheet"> <link href="../../hplus/plugins/hjk/plugins/bootstrap-select-1.12.1/css/bootstrap-select.min.css" rel="stylesheet"> <link href="../../hplus/plugins/hjk/plugins/DataTables/css/data-table.css" rel="stylesheet"> </head> <!--解決表格標題內容居中問題--> <style> table tr td{ text-align: center!important; } table tr th{ text-align: center!important; } </style> <body class="gray-bg"> <form class="form-horizontal form-bordered" data-parsley-validate="true" name="bgPicture-form" id="bgPicture-form"> <div class="modal-body"> <div class="form-group"> <div class="row"> <div class="col-sm-12" > <div class="ibox "> <div class="ibox-content"> <form class="form-horizontal form-bordered" id="queryForm"> <div class="form-group"> <div class="col-md-4 "> <div class="input-group"> <span class="input-group-addon">提問內容:</span> <input id="description" type="text" class="form-control"> </div> <div class="input-group"> <span class="input-group-addon">提問人:</span> <input id="username" type="text" class="form-control"> </div> </div> <div class="col-md-4 "> <div class="input-group"> <button type="button" class="btn btn-primary m-r-5 m-b-5" id="query">查詢</button> </div> </div> <div class="col-md-4 "> <div class="input-group"> <button type="button" id="submitContentBtn" class="btn btn-sm btn-primary">檢視詳情</button> </div> </div> </div> </form> <hr> <div class="table-responsive"> <table id="data-table" class="table table-striped table-bordered display" cellspacing="0" width="100%"> <thead> <tr> <th> <input type="checkbox" class="checkall" /> </th> <th >ID</th> <th >提問人</th> <th >提問內容</th> <th >提問時間</th> <th >圖片數量</th> <th >回覆人</th> </tr> </thead> <tbody id="tbodyId"> <tr> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> </tr> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> </form> <script src="../../hplus/js/jquery.min.js?v=2.1.4"></script> <script src="../../hplus/js/content.min.js?v=1.0.0"></script> <script src="../../hplus/plugins/hjk/js/bootstrap-treeview.js"></script> <script src="../../hplus/plugins/hjk/plugins/gritter/js/jquery.gritter.js"></script> <script src="../../hplus/plugins/hjk/plugins/parsley/dist/parsley.js"></script> <script src="../../hplus/plugins/hjk/plugins/jquery/jquery.form.js"></script> <script src="../../hplus/plugins/hjk/plugins/jquery-confirm/jquery-confirm.min.js"></script> <script src="../../hplus/plugins/hjk/plugins/bootstrap-select-1.12.1/js/bootstrap-select.min.js"></script> <script src="../../hplus/plugins/hjk/plugins/bootstrap-select-1.12.1/js/i18n/defaults-zh_CN.min.js"></script> <script src="../../hplus/plugins/hjk/plugins/switchery/switchery.min.js"></script> <script src="../../hplus/plugins/hjk/plugins/DataTables/js/jquery.dataTables.js"></script> <script src="../../hplus/js/bootstrap.min.js?v=3.3.6"></script> <script> $(document).ready(function () { //初始化按鈕繫結事件 $("#query").click(function(){ t.ajax.reload(); }); var t=null; t=$("#data-table").DataTable( { "processing":true, "serverSide":true, "pageLength": 10, //首次載入的資料條數 "ordering": false, //排序操作在服務端進行,所以可以關了。 "paging":true, "pagingType": "full_numbers", "autoWidth": false, "searching": false,//禁用搜索 "columns": [ //序號 { "sClass": "text-center", "data": "id", "render": function (data, type, full, meta) { return '<input type="checkbox" class="checkchild" value="' + data + '" />'; }, "bSortable": false }, //ID {"data": "id"}, //提問人 { "data": "openid" }, //提問詳情 { "data": "description"}, //提問時間 { "data": "gmtCreate" }, //圖片數 { "data": "imageNumber" }, //回覆人 { "data": "replyName" } ], "ajax":{ type: "get", url:'/quiz/service', data: function (d) { var param = {}; param.draw = d.draw; param.start = d.start; param.length = d.length; //獲得提問人搜尋條件 var username = $("#username").val(); //給請求新增條件 if(username!=undefined){ param.username = username; } //獲得提問人搜尋條件 var description = $("#description").val(); //給請求新增條件 if(description!=undefined){ param.description = description; } return param;//自定義需要傳遞的引數。 } } } ); }); /*檢視內容詳情*/ $("#submitContentBtn").click(function () { //獲取選中的某一個checkbox的值 if ($(".checkchild:checked").length > 1){ $.alert({ title: '提示', content: '一次只能選擇一條資料!', }); return; }else if($(".checkchild:checked").length == 0){ $.alert({ title: '提示', content: '請選擇一條資料!', }); return; } //獲取ID var id = $(".checkchild:checked").val(); //ID存入localStorage會話中 localStorage.setItem("id",id) //載入詳情頁 window.location.href="/quiz/details"; }); </script> </body> </html>
分頁封裝實體類:
package com.zenithink.spp.cms.util;

import java.util.List;

public class Datatables<T> {  
//每頁顯示集合
    private List<T> data;//LIST(結果集)
//總記錄數
private long recordsTotal;

    private long recordsFiltered;
//請求次數
    private long draw;

    public Datatables() {  

    }

    public long getDraw() {
        return draw;
    }

    public void setDraw(long draw) {
        this.draw = draw;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public long getRecordsTotal() {
        return recordsTotal;
    }

    public void setRecordsTotal(long recordsTotal) {
        this.recordsTotal = recordsTotal;
        this.recordsFiltered = recordsTotal;
    }

    public long getRecordsFiltered() {
        return recordsFiltered;
    }

    public void setRecordsFiltered(long recordsFiltered) {
        this.recordsFiltered = recordsFiltered;
    }  
} 
接下來是後臺程式碼:
/**
 * 提問模組分頁
* @param draw 請求次數
* @param start 
            
           

相關推薦

基於springBoot+DataTables外掛實現

這個外掛我感覺挺好用,配置也簡單,自帶條件物件,下面我就以我的專案程式碼來說明:首先重要的兩個依賴:<script src="../../hplus/plugins/hjk/plugins/DataTables/js/jquery.dataTables.js">

SpringBoot下dataTable實現

dataTable的分頁可以前端實現,但是前端實現的分頁是假分頁(從後臺獲取所有資料,再快取分頁處理),這樣做確實方便開發,但是隨著資料量逐漸增大,查詢的訊息越來越低,每次都在查詢的時候卡住幾秒。所以假分頁相當不實用了。 在分頁前,自己做了一個簡單的分頁資料量查詢測試,分

django datatables外掛 表格

有了datatables外掛不需要自己寫分頁功能,而且datatables功能強大。 官方文件地址:https://datatables.net/examples/ajax/objects.html <!DOCTYPE html> <html lang="en">

基於jquery的簡單實現

先上圖: 之前在做表格外掛想把分頁整合進去,原本去網站找一個現成的整合進去,發現有些太簡單或者很複雜,達不到自己的要求,自己想還是自己整一個,順便了解一下其中的原理。 分頁樣式是基於boosta

Springboot 使用PageHelper外掛實現

一、pom檔案中引入依賴 二、application.properties中配置以下內容 pagehelper.helper-dialect=mysqlpagehelper.reasonable=truepagehelper.support-methods-arguments=truepagehelp

SpringBoot整合MyBatis外掛PageHelper

原創作品,可以轉載,但是請標註出處地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分頁外掛PageHelper 步驟 第一步:首先整合MyBatis 參照之前SpringBoot整合MyBatis.md 第二步

springboot+Mybatis的外掛pageHelper

1、在pom.xml加入pageHelper依賴包 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>page

SpringBoot 整合 PageHelper無法實現

解決:三個依賴都要引入 <!-- PageHelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pa

springboot使用pagehelper外掛時出錯

簡單說一下 問題  1.pom中pagehelper的依賴 <!-- springboot分頁外掛 --> <dependency> <groupId>com.github.pagehelper</groupId>

Mybatis-利用Mybatis Generator外掛生成基於資料庫方言的語句,統計記錄總數

眾所周知,Mybatis本身沒有提供基於資料庫方言的分頁功能,而是基於JDBC的遊標分頁,很容易出現效能問題。網上有很多分頁的解決方案,不外乎是基於Mybatis本機的外掛機制,通過攔截Sql做分頁。但是在像Oracle這樣的資料庫上,攔截器生成的Sql語句沒有變數繫

基於vue.js的外掛

先說點別的,今天冬至,前幾天上海又一次比較大的降溫,把我一個北方人凍成了狗,就在前天,晴空萬里,烈日當頭,於是我脫掉了我的秋褲,然而,明天降10°C,我有點不知所措了。☆★☆★☆★☆★☆★☆★☆★☆★☆

從零學springboot——springboot新增mybatis外掛

新增分頁外掛依賴 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId>

基於spring boot架構和word詞器的詞檢索,排序,實現

       本文不適合Java初學者,適合對spring boot有一定了解的同學。 文中可能涉及到一些實體類、dao類、工具類文中沒有這些類大家不必在意,不影響本文的核心內容,本文重在對方法的梳理。    word分詞器maven依賴<dependency>

基於bootstrap的簡單前端介面實現

①效果圖②bootstrap基本模板<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compati

Gradle構建SpringBoot+Mybatis整合外掛PageHelper

使用Gradle構建SpringBoot專案,使用Mybatis來持久化,嘗試整合PageHelper分頁外掛,依然順利都令到我吃驚,so easy! 首先,build.gradle中配置依賴 dependencies { compile gro

基於SSM和jstl的實現

以前用jsp和原生的JDBC實現過分頁,現在一看,不僅程式碼冗餘,而且可讀性差,今天分享一種簡潔的實現方式,我用起來是很方便的。 一.概述 主要思想就是建一個Page類,所有跟分頁有關的引數都放在這個類裡,這個類裡放一個集合用來裝返回的資料,前端用JST

基於nodejs的簡單實現

一、專案描述 這個demo是基於昨天我寫的增刪改查的例子的。在昨天的例子的基礎上,我增加了基本的分頁功能。由於本人對於nodejs的理解不夠深入所以在分頁實現上,有很多不足之處。在儲存分頁資訊上我使用的是request層儲存,也就是用get傳值的古老辦法,主要是由於對於no

mybatis實現(非外掛方式)

前面一篇文章介紹了通過攔截器發方式實現mybatis分頁(應該是比較常用的一種方式,網上搜索結果較多),這裡介紹另一種方式:通過程式碼封裝,不改變mybatis框架的任何東西(個人推薦使用該方式),這個程式碼是我老大寫的,個人覺得很好,原理也很簡單,修改也很容易,所以貼出來

springboot實現

本次要講的是典型的兩種分頁方式,即sql分頁和外掛分頁。 依賴 因為使用了mybatis、mysql ,所以要新增相關依賴。這裡版本沒有特別需求,選擇你想要的版本即可。 <!--mybatis-->

springboot +mybatis + pagehelper外掛

分頁的方法有很多,今天記錄下一種使用基於物理分頁原理實現分頁的外掛pagehelper與springboot+mybatis的整合: 1、首先在pom.xml檔案中新增pagehelper依賴包: