分页JQ+模糊查询

--页面

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit|ie-stand">
<title>爱抚州-新媒体综合运营中心</title>
<link href="${base}/res/vms/skin/css/base-style.css" rel="stylesheet" type="text/css">
<link href="${base}/res/vms/skin/css/system-style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="${base}/res/vms/skin/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/res/vms/skin/js/iframe-common.js"></script>

<link rel="shortcut icon" href="${base}/res/sui-build/docs/pictures/logo.png?r=2014.06.18">
<link id="docs-css" href="${base}/res/sui-build/docs/assets/css/docs.css?r=2014.06.30" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="${base}/res/sui-build/docs/assets/css/animate.css" />
<link type="text/css" rel="stylesheet" href="${base}/res/sui-build/docs/assets/js/google-code-prettify/prettify.css" />
<script src="${base}/res/sui-build/.package/js/sui.js?r=2014.06.30"></script>
<script src="${base}/res/sui-build/docs/assets/js/google-code-prettify/prettify.js"></script>
<script src="${base}/res/sui-build/docs/assets/zeroclipboard/ZeroClipboard.js"></script>
<script src="${base}/res/sui-build/docs/assets/js/application.js"></script>
<script type="text/javascript">
var themesUrl = "${base}/res/sui-build/.package/css/sui.css";
var themesAppendUrl = "${base}/res/sui-build/.package/css/sui-append.css";
var selected = localStorage.getItem("themes-name");
if(selected && !(selected == 'default')) {
themesUrl = '${base}/res/sui-build/.package/css/sui-themes-' + selected + ".css";
themesAppendUrl = '${base}/res/sui-build/.package/css/sui-themes-' + selected + "-append.css";
$(function() {
var $select = $("#themes-select");
var $current = $select.find("[value='"+selected+"']");
$current.parent().addClass("active");
$select.find(">a > span").html($current.text())[0].className = $current[0].className;
});
}
$('<link href="' + themesUrl + '?r=2014.09.11" rel="stylesheet" id="sui-css" charset="utf-8">').insertBefore($("#docs-css"));
$('<link href="' + themesAppendUrl + '?r=2014.09.11" rel="stylesheet" id="sui-css-append" charset="utf-8">').insertBefore($("#docs-css"));
$(function(){
var OId = $('#OId').val();
//分页初始化
$('#pg').pagination({
pages: ${page.totalPage },//总页数
styleClass: ['pagination-large'],
showCtrl: true,
displayPage: 5,
currentPage:${page.currentPage },//当前页数
onSelect: function (number) {
//跳转到点击的页面
location.href="SY_timeliftinfoList.do?currentPage="+number+"&OId="+OId
}
});
});
</script>

<script type="text/javascript">
$(function() {
$("#checkAll").click(function(){
if(this.checked){
$("#js_checkbox :checkbox").prop("checked", true);
}else{
$("#js_checkbox :checkbox").prop("checked", false);
}
});
});
</script>

<script type="text/javascript">
function d1(btn) {
var id = btn.getAttribute("id");/* $(btn).attr */
if(confirm("确定删除吗")) {
window.location.href="deleteAll.do?id="+id;
}
}
</script>
</head>
<body>
<div class="jkss-box-warp">
<div class="jkss-box-area">
<div class="jkss-box layout-justify">
<div class="dib-t jk-top-btn">
<a href="../../index1.do" class="dib-t g32-btn return-btn">返回</a>
<a href="SY_addtimeliftinfo.do" class="f32-btn dib-t">新建时移</a>
<a href="javascript:;" id="del-vod" class="f32-btn dib-t">删除</a>
</div>
<div class="dib-t jk-top-ss">
<form action="http://localhost:8080/afz/jeeadmin/jeecms/vms/media_main/SY_timeliftinfoList.do" class="dib-t jk-ss-form">
<input type="text" class="text-box-30" placeholder="输入搜索内容" name="OId" id="OId" value="${OId!}">
<input type="submit" value="搜索" class="b32-btn search-btn">
</form>
</div>
<div class="last-justify"></div>
</div>
</div>
</div>
<div class="vod-list-area js_vod_list_area">
<div class="iframe-padding">
<div class="sljh-table">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="js_checkbox">
<thead>
<tr>
<th width="8%" >
<label class="i-checks">
<input type="checkbox" id="checkAll">
<i></i>
</label>
</th>
<th width="12%" >节目名称</th>
<th width="12%" >频道</th>
<th width="40%" >节目开始时间-结束时间</th>
<th width="16%" >添加人/时间</th>
<th width="20%" >操作</th>
</tr>
</thead>
<tbody>
<#list list as list>
<tr>
<td >
<label class="i-checks">
<input type="checkbox" name="subBox" value="${list.id}">
<i></i>
</label>
</td>
<td>${list.programname}</td>
<#if list.type=0><td>全部频道</td>
<#elseif list.type=1><td>抚州一套</td>
<#elseif list.type=2><td>抚州二套</td>
</#if>
<td >${list.starttime} - ${list.endtime}</td>
<td >${list.name} : ${list.date}</td>
<td class="wz-list-btn">
<a onclick="d1(this)" id="${list.id}" class="del" title="删除"></a>
</td>
</tr>
</#list>
</tbody>
</table>
</div>
<div id="pg" style="margin:0px auto;text-align:center;"></div>
</div>
</div>
</body>
</html>

--后台

dao层

public List<Timeliftinfo> list(String OId,Page page) {
String hql = "";
if(OId != null) {
hql = "from Timeliftinfo where programname like '%"+OId+"%'";

} else {
hql = "from Timeliftinfo";
}
Query query = getSession().createQuery(hql).setFirstResult((page.getCurrentPage()-1)*page.getPageSize()).setMaxResults(page.getPageSize());
List<Timeliftinfo> list = query.list();
return list;

}

public int count(String OId) {
String hqlcount = "";
if(OId != null) {
hqlcount="select count(*) from Timeliftinfo where programname like '%"+OId+"%'";
} else {
hqlcount="select count(*) from Timeliftinfo";
}
Query querycount = getSession().createQuery(hqlcount);
Integer totalCount=Integer.parseInt(querycount.uniqueResult().toString());
return totalCount;

}

service层调用,action层

@RequestMapping(value = "/vms/media_main/SY_timeliftinfoList.do")
public String SY_timeliftinfoList(ModelMap model,String OId,Page page,HttpServletRequest request) {
try {
page.setTotalCount(timeService.count(OId));
page.setPageSize(10);
int currentPage = 1;
if(request.getParameter("currentPage") != null) {
currentPage = Integer.parseInt(request.getParameter("currentPage"));
}
page.setCurrentPage(currentPage);
List<Timeliftinfo> list = timeService.list(OId,page);
model.addAttribute("list", list);
model.addAttribute("OId", OId);
request.setAttribute("page", page);
} catch (Exception e) {
e.printStackTrace();
}
return "vms/media_main/SY_timeliftinfoList";
}

--实体类

package com.jeecms.test.entity;

import java.io.Serializable;

public class Page implements Serializable {

private int pageSize;//每页显示的记录数
private int totalCount;//总共的记录数
private int totalPage;//总共页数 totalPage=totalCount%pageSize==0?totalPage=totalCount/pageSize:(totalPage=totalCount%pageSize+1)
private int currentPage;//当前页数
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage=totalCount%pageSize==0?totalPage=totalCount/pageSize:(totalPage=totalCount/pageSize+1);
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}


}
原文地址:https://www.cnblogs.com/jietz0407-com/p/6365912.html