溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

springboot集成html中分頁功能如何實(shí)現(xiàn)

發(fā)布時(shí)間:2020-10-26 11:34:12 來源:億速云 閱讀:215 作者:小新 欄目:web開發(fā)

小編給大家分享一下springboot集成html中分頁功能如何實(shí)現(xiàn) ,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

直接上代碼和展示效果:

前臺(tái):

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <title>陪米app后臺(tái)主頁</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/page_common.js"></script>
	<link href="/css/common_style_blue.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="/css/index_1.css" />
	<script type="text/javascript">
		var pageNo = 1;
		var pageSize = 8;
		var pages = 0;
	//<![CDATA[	
	 $(document).ready(function(){	
		 var key = $("#keyword").val();
		 	loadData(key,pageNo,pageSize);
		 });		 
		function loadData(key,pageNo,pageSize){
			 	$.ajax({
					url:"/web/getReport",
					type:"post",
					data:{keyword:key,pageNo:pageNo,pageSize:pageSize},
					success:function(data){					
					var json = eval('('+data + ')');
						console.log(data);
						var html="";																						
//					    var reportlisthtml='';						   
						var maojungang = json.data;
//						var message = json.message;
						var totalCount = json.total;
						 pages = Math.ceil(totalCount/pageSize);
//						alert(message);
						for(var i in maojungang){ 						
					html=html+"<tr>"+
				"<td>"+maojungang[i].byReportUser+"&nbsp;"+maojungang[i].byReportName+"&nbsp;</td>"+
				"<td>"+"<textarea>"+maojungang[i].content+"</textarea>"+"&nbsp;</td>"+
				"<td>"+maojungang[i].timed+"&nbsp;</td>"+
				"<td>"+maojungang[i].friendId+"&nbsp;</td>"+
				"<td>"+maojungang[i].taskId+"&nbsp;</td>"+
                "<td>"+maojungang[i].reportUser+"&nbsp;"+maojungang[i].reportName+"&nbsp;</td>"+"</tr>";


							} 				
//					   $('#TableData').html(reportlisthtml); 
						$("#TableData").html(html);	
						    var newText = "共" + totalCount + "條," + "第" + pageNo + "頁," + "共" + pages + "頁";
    						$("#summary").text(newText);
																	
					}
				}); 					
			}		
		 function search(){
//		 	loadData($("#keyword").val());
 			var key = $.trim($("#keyword").val().trim());
			loadData(key,pageNo,pageSize);
		 }
		 
		 function index(){	
			 pageNo = 1;			 	 		
		   var key = $.trim($("#keyword").val().trim());
		  loadData(key,pageNo, pageSize);
		 }
		 function last(){
			var key = $.trim($("#keyword").val().trim());
		  if(pageNo == 1){
		        return false;
		    } else{
		        pageNo--;
		        loadData(key,pageNo, pageSize);
		    }
		 }
		 function next(){
		 var key = $.trim($("#keyword").val().trim());
		 	 if(pageNo == pages){
		        return false;
		    } else{
		        pageNo++;
		        loadData(key,pageNo, pageSize);
		    }
		 }
		 function zuihou(){
		 	pageNo = pages;
		 	var key = $.trim($("#keyword").val().trim());
		    loadData(key,pageNo, pageSize);
		 }
		 function pageNumber(){
		 	var pageNumber = $.trim($("#pageNumber").val().trim());
		 	 var key = $.trim($("#keyword").val().trim());
		 	pageNo = pageNumber;
		 	loadData(key,pageNo, pageSize);
		 }		 		 		 
		//]]>
	</script>


</head>
<style>
	textarea{
		height:50px;
		width: 80%;
	}
	.tnd{		
		text-align:center;
		width:100%;
		height:50px;
		border: solid;
		padding:10px;
		border: 2px solid #000000;
		-moz-border-radius: 15px;
	    -webkit-border-radius: 15px;
	    border-radius:15px;
	    background-color:aqua;
	    
	    }
	    .tnds{
		font-size:25px;
		
		width:98.7%;
		height:30px;
		border: solid;
		padding:10px;
		border: 2px solid #000000;
		-moz-border-radius: 15px;
	    -webkit-border-radius: 15px;
	    border-radius:15px;
	    background-color:aqua;
	    color: #551A8B;
	    }
	     .tndss{
		font-size:25px;
		text-align:center;
		width:98.7%;
		height:800px;
		border: solid;
		padding:10px;
		border: 2px solid #000000;
		-moz-border-radius: 15px;
	    -webkit-border-radius: 15px;
	    border-radius:15px;
	    background-color:aqua;
	    color: #551A8B;
	    }
	.content{
		float: left;
		margin-left: 1.8%;
		width:91%;
		height: 900px;
		margin-top: 88px;
		text-align:center;	
		border: solid;	
		border: 2px solid #000000;
		-moz-border-radius: 15px;
	    -webkit-border-radius: 15px;
	    border-radius:15px;
	}
	.tab{
		align="center";
	    cellspacing="0";
	    cellpadding="0";
		height: 300px;
	    table-layout:fixed;
    empty-cells:show; 
    border-collapse: collapse;
    margin:0 auto;
	}
</style>
<body>
<p style="width: 100%;height: 1080px;background-image:url('/image/girldd.jpg') ;position:fixed;top:0;z-index:999;">
	<p style="width: 100%;background-color: aqua;position:fixed;top:0;z-index:999;">
			<p style="margin-left: 40%;margin-right: 50%;width: 30%">
				<h2 style="font-size: 30px;color: #551A8B" >陪米后臺(tái)主頁</h2>
			</p>
			
	</p>
	<p style="margin-top: 90px;float: left;margin-left: 0%;">  
		<a href="/web/reportlist" ><p class="tnd">
			<p style="margin-top: 15px;font-size: 18px">
			  舉報(bào)信息查詢
			</p>
		</p></a>
		<a href="/web/getReport" ><p class="tnd">
			<p style="margin-top: 15px;font-size: 18px">
			 用戶信息查詢
			</p>
		</p></a>
		<a href="/web/getReport" ><p class="tnd">
			<p style="margin-top: 15px;font-size: 18px">
			  不良信息刪除
			</p>
		</p></a>
		<a href="/web/getReport" ><p class="tnd">
			<p style="margin-top: 15px;font-size: 18px">
			  用戶賬戶封禁
			</p>
		</p></a>
		<a href="/web/getReport" ><p class="tnd">
			<p style="margin-top: 15px;font-size: 18px">
			  用戶意見反饋
			</p>
		</p></a>
		
     </p> 
     <p class="content" > 
         <p class="tnds">
			<p style="text-align: left;float: left;">舉報(bào)信息</p>
			<p style="text-align: center;font-size: 15px;float: left;margin-left: 19.95%;margin-top: 10px">
				<form action="">
				請(qǐng)輸入舉報(bào)時(shí)間:	<input id="keyword" name="timed" class="" placeholder="yyyy-MM-dd"/>
					<input type="button" value="搜索" onclick="search()"/>
				</form>
			</p>
		</p>
		
<!-- 主內(nèi)容區(qū)域(數(shù)據(jù)列表或表單顯示) -->
<p class="tndss">
    <table  class="tab" >
        <!-- 表頭-->
        <thead>
            <tr align="center" >
				<td style="width: 10%">被舉報(bào)人ID</td>
				<td style="width: 50%">舉報(bào)內(nèi)容</td>
				<td style="width: 10%">舉報(bào)時(shí)間</td>
				<td style="width: 10%">朋友圈ID</td>
				<td style="width: 10%">任務(wù)ID</td>
                <td style="width: 10%">舉報(bào)人ID</td>				
			</tr>
			
		</thead>	
		<!--顯示數(shù)據(jù)列表 -->
         <tbody id="TableData" style="color: red; ">


        </tbody>
    </table>
	
   <!-- 其他功能超鏈接 -->


    <p id="footer">
    <span id="summary"></span>
    <ul id="pagination">
        <li id="01"><a onclick="index()" style="font-size: 25px">首頁</a></li>
        <li id="02"><a onclick="last()" style="font-size: 25px" >上一頁</a></li>
        <li id="03"><a onclick="next()" style="font-size: 25px">下一頁</a></li>
        <li id="04"><a onclick="zuihou()" style="font-size: 25px">最后一頁</a></li>
    </ul>
    <p id="select">
        <span>跳轉(zhuǎn)到 </span>
        <input type="text" name="page_num" id="pageNumber"/>
        <span> 頁  </span>
        <input type="button" name="go_btn" value="跳轉(zhuǎn)" onclick="pageNumber()"/>
    </p>
  </p>
</p>	     
     </p>
            
             
</p>
</body>
</html>
后臺(tái):
package com.hpm.blog.controller;


import java.util.ArrayList;
import java.util.List;


import javax.servlet.http.HttpSession;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.fasterxml.jackson.annotation.JsonFormat.Value;
import com.hpm.blog.model.AdminUser;
import com.hpm.blog.model.ReportVo;
import com.hpm.blog.model.ReturnResult;
import com.hpm.blog.service.AttentionService;
import com.hpm.blog.service.ReportService;
import com.hpm.blog.util.Constant;
import com.hpm.blog.util.Constants;
import com.hpm.blog.util.Page;
import com.hpm.blog.util.ResultData;


@Controller
@RequestMapping("/web/")
public class ReportController {
	
	private static final Logger logger = LoggerFactory.getLogger(AttentionService.class);
	@Autowired
	private ReportService reportService;
	
	@RequestMapping("getReport")
	@ResponseBody
	public ReturnResult getReport(HttpSession session,Model model,String keyword,String pageNo,String pageSize){
		ReturnResult result = new ReturnResult();
		try {		
			Page page = new Page();
			page.setPageNo(Integer.valueOf(pageNo));
			page.setPageSize(Integer.valueOf(pageSize));
			AdminUser adminUser = (AdminUser) session.getAttribute(Constants.USER_SESSION);
			List<ReportVo> list = new ArrayList<ReportVo>();
			if(null != adminUser){
				if(null == keyword || "".equals(keyword)){
					list= reportService.queryAll(page);
					int total = reportService.queryAllCount(page);
					result.setTotal(total);
					result.setData(list);
					result.setCode(Constant.SUCCESS_CODE);
					result.setMessage("查詢成功!");
				}else{
					list= reportService.queryByKeyword(keyword,page);
					int total = reportService.queryAllCountBykey(page,keyword);
					result.setTotal(total);
					result.setData(list);
					result.setCode(Constant.SUCCESS_CODE);
					result.setMessage("查詢成功!");
				}		 
			}else{
				result.setCode(Constant.ERROR_CODE);
				result.setMessage("身份失效,請(qǐng)重新登錄");
			}
		} catch (Exception e) {
			// TODO: handle exception
			logger.debug("error = " + e.getClass().getSimpleName()+" "+e.getMessage());
			result.setCode(Constant.ERROR_CODE);
			result.setMessage("信息獲取失??!請(qǐng)稍后重試.....");
		}
		return result;
	}


}

效果:

springboot集成html中分頁功能如何實(shí)現(xiàn)

點(diǎn)擊舉報(bào)查詢:

springboot集成html中分頁功能如何實(shí)現(xiàn)

點(diǎn)擊下一頁:

springboot集成html中分頁功能如何實(shí)現(xiàn)

輸入頁碼跳轉(zhuǎn):

springboot集成html中分頁功能如何實(shí)現(xiàn)

輸入時(shí)間搜索:

springboot集成html中分頁功能如何實(shí)現(xiàn)

帶著時(shí)間參數(shù)分頁:

springboot集成html中分頁功能如何實(shí)現(xiàn)

以上是springboot集成html中分頁功能如何實(shí)現(xiàn) 的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI