script:
<script type="text/javascript">
$(function(){
//var ctx = [[@{/}]];
httpPost = function(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
httpGet = function(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "get";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
//处理分页
var pageNo = parseInt($("#pageNo").val());
//下一页
nextPage = function (){
var pageCount = parseInt($("#pageCount").text());
//alert(pageCount);
if(pageCount>pageNo){
pageNo = pageNo+1;
$("#pageNo1").text(pageNo);
$("#pageNo2").text(pageNo);
alert(pageNo+"pageCount"+pageCount);
//window.location.href = ctxPath+"/index?page="+pageNo;
httpGet("index",{"pageNo":pageNo});
}
}
//上一页
prePage = function (){
if(pageNo>1){
pageNo = pageNo-1;
$("#pageNo1").text(pageNo);
$("#pageNo2").text(pageNo);
alert(pageNo+">1");
//window.location.href = ctxPath+"/jkfwList?page="+pageNo;//改
httpGet("index",{"pageNo":pageNo});
}
}
//跳转到任意页
$("#pageGoTo").click(function(){
pageNo = parseInt($("#page").val())-1;
//alert(pageNo);
//window.location.href = ctxPath+"/jkfwList?page="+pageNo;//改
httpGet("index",{"pageNo":pageNo});
});
//删除
deleteUser = function(userId){
Dialog.confirm('警告:您确认要删除吗?',function(){
$(function(){
$.ajax({
type:"post",
url:"deleteUser",
data:{"userId":userId},
dataType:"json",
success:function(res){
if(res.status == '1'){
Dialog.alert("删除成功!",function(){
//window.location.href = "@{|/index|}";
httpGet("index","");
});
}else{
Dialog.alert("删除失败!");
}
}
});
});
});
}
});
</script>
html:
<div class="list-footer">
<div class="list-page">
<ul class="list-pagecontent" style="list-style:none;">
<li><a class="leftborder"> « </a></li>
<li><a onclick="prePage()"> < </a></li>
<li><a class="active" id="pageNo1" th:text="${pageNo}+1">1</a></li>
<li class="disabled"><a onclick="nextPage()"> > </a></li>
<li class="disabled"><a> » </a></li>
<li class="pageGoto"><span>总记录</span> <span class="num" th:text="${userCount}">8</span>
<span>总页数</span> <span id="pageCount" class="num" th:text="${pageCount}">1</span>
<span>当前第</span>
<span class="num" id="pageNo2" th:text="${pageNo}+1">1</span> <span>页</span>
<span>转到</span>
<input type="text" id="page" name="page" class="input pageInput" th:value="${pageNo}+1"/>
<span>页</span>
<input type="button" class="btn blue" id="pageGoTo" value="确定" />
</li>
</ul>
<input id="pageNo" type="hidden" th:value="${pageNo}" />
</div>
</div>
controller:
public String serverList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "page.size", defaultValue = PAGE_SIZE) int pageSize,
@RequestParam(value = "order.field", defaultValue = "FW_LX") String orderField,
@RequestParam(value = "order.sort", defaultValue = "ASC") String orderSort,
Model model,ServletRequest request){
try {
//初始化分页数据
PageUtils pageUtils=new PageUtils(pageNo*pageSize,pageSize,orderField,orderSort);
//搜索属性初始化
//Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
List<Map<String, Object>> userList = new ArrayList<>();
userList = userListService.usersBypage(pageUtils);
int userCount = userListService.finduSerCount();
int pageCount = (userCount/Integer.parseInt(this.PAGE_SIZE))+1;
model.addAttribute("pageCount", pageCount);
model.addAttribute("userCount", userCount);
//model.addAttribute("padeCount", jkfwCount);
model.addAttribute("pageNo",pageNo);
model.addAttribute("userList",userList);
System.out.println(userList);