使用ajax分页查询
controller:
- /**
* 查询所有用户/查找指定用户
* 分页+搜索
*
*/
@RequestMapping("/findClientBySize")
@ResponseBody
public String findClientBySize(ClientUser clientUser,String userPhone,String userName, Integer currentPage, Integer pageSize)throws Exception{
if(currentPage == null || currentPage.equals("")){
currentPage = 1;
}
if(pageSize == null || currentPage.equals("")){
pageSize = 10;
}
int startRow = (currentPage-1)*pageSize;
int endRow = pageSize;
List<ClientUser>list= clientUserService.findAllClient(clientUser);
List<ClientUser> list2= clientUserService.findClientBySize(clientUser,userPhone,userName,startRow,endRow);
PageResult pageResult = new PageResult(currentPage,list.size(),pageSize,list2);
return JSON.toJSONString(pageResult);
}
domain:
- package com.hpwl.domain;
- import java.util.List;
- /**
* Created by mayn on 2019/1/15.
*/
public class PageResult {
private int currentPage;//当前页
private int prevPage;//上一页
private int nextPage;//下一页
private int countSize;//一共几条数据
private int maxPage;//最后一页
private int pageSize;//每页显示条数
private List dataList;//返回的数据集- public int getCurrentPage() {
return currentPage;
}- public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}- public int getPrevPage() {
return prevPage;
}- public void setPrevPage(int prevPage) {
this.prevPage = prevPage;
}- public int getNextPage() {
return nextPage;
}- public void setNextPage(int nextPage) {
this.nextPage = nextPage;
}- public int getCountSize() {
return countSize;
}- public void setCountSize(int countSize) {
this.countSize = countSize;
}- public int getMaxPage() {
return maxPage;
}- public void setMaxPage(int maxPage) {
this.maxPage = maxPage;
}- public int getPageSize() {
return pageSize;
}- public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}- public List getDataList() {
return dataList;
}- public void setDataList(List dataList) {
this.dataList = dataList;
}
public PageResult(int currentPage, int countSize, int pageSize,List dataList) {
super();
this.currentPage = currentPage;
this.countSize = countSize;
this.pageSize = pageSize;
this.dataList = dataList;- this.prevPage = currentPage > 1 ? this.currentPage - 1 : 1;
- this.maxPage = countSize % pageSize == 0 ? countSize/pageSize : countSize/pageSize+1;
- this.nextPage = currentPage >= maxPage ? maxPage :currentPage + 1;
}- public PageResult() {
super();
}
}- mapper:
- List<ClientUser> findClientBySize(ClientUser clientUser, @Param("userPhone")String userPhone, @Param("userName")String userName, @Param("startRow")int startRow, @Param("endRow")int endRow);
- mapper.xml:
- <select id="findClientBySize" resultType="ClientUser" >
- select * from
client_user
<where>
1=1
<if test="userName!=null and userName!='' ">
and user_name=#{userName}
</if>
<if test="userPhone!=null and userPhone!=''">
and user_phone=#{userPhone}
</if>
</where>
limit
#{startRow},#{endRow}- </select>
- jsp页面
- <script type="text/javascript">
function toPage(currentPage){
$.ajax({
url:"${pageContext.request.contextPath}/AdminClient/findClientBySize",
data:{"currentPage":currentPage},
type: 'POST',
dataType: 'json',
success: function(data){
var a=null;
/*var jsonData = JSON.parse(data); //jsonData是该下路下的所有区间(json格式)
*/
var data1=data.dataList;
console.log(data);
console.log(data.dataList);
$("tbody").html('');
$.each(data1,function (index,obj) {- var tr0 = '<tr class="text-c">' +
'<td><input type="checkbox" value="'+obj.id+'" name=""></td>' +
'<td><u style="cursor:pointer" class="text-primary">'+obj.userName+'</u></td>' +
'<td>'+obj.userPwd+'</td>'+
'<td>'+obj.usernick+'</td>'+
'<td>'+obj.userPhone+'</td>'+
'<td>'+obj.datetime+'</td>'+
'<td>'+obj.chack+'</td>'+
'<td>'+obj.userName+'</td>'+
'<td class="td-manage">'+
'<a style="text-decoration:none" onClick="member_start(\'this\','+obj.id+')" href="javascript:;" title="启用"><i class="Hui-iconfont"></i></a> '+
'<a style="text-decoration:none" onClick="member_stop(\'this\','+obj.id+')" href="javascript:;" title="停用"><i class="Hui-iconfont"></i></a> '+
'<a title="编辑" href="javascript:;" onclick="member_edit(\'编辑\',\'member-up.jsp\','+obj.id+',\'800\',\'510\')" class="ml-5" style="text-decoration:none">'+
'<i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="change_password(\'修改密码\',\'change-password.jsp\','+obj.id+',\'600\',\'270\')" href="javascript:;" title="修改密码">'+
'<i class="Hui-iconfont"></i></a> <a title="删除" href="javascript:;" onclick="" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a></td>'+
'</tr>';- $("tbody").append(tr0);
});- $("tfoot").html('');
var tr1 = '<tr class="text-c"><td colspan="10" style="text-align: right"> <a href="javascript:toPage('+data.prevPage+')" >上一页</a> <a href="javascript:toPage('+data.nextPage+')" >下一页</a></td></tr>';
$("tfoot").append(tr1);
},
});
};
- $(function(){
toPage(1);
});
使用ajax分页查询的更多相关文章
- ajax分页查询
(1)先写个显示数据的页面,分页查询需要那几个部分呢? 1.首先是查询的文本框输入,还有查询按钮,那么就开始写代码吧 1 2 3 4 <div> <input type=" ...
- ajax分页查询信息的通用方法
1.页面准备分页的表格与分页div 同时需要在查询条件表单中准备隐藏当前页与页大小的文本框 <div class="container-fluid"> <div ...
- springMVC+ajax分页查询
项目用到ajax技术的查询,查询结果很多时候要分页展示.这两天摸索了一下,在这里做一总结,方便自己随时查看, 也方便后人参考. 这里的顺序遵从从前台页面到后台控制器,业务层,Dao层,Mapper 下 ...
- kkpager 实现ajax分页查询
前台分页数据,适合数据少量的时候,因为分页的数据是从后台获取的,大数据的话不建议使用 现看前台代码: @{ Layout = null; } <!DOCTYPE html> <htm ...
- Ajax写分页查询(实现不刷新页面)
获取数据库中大量的信息显示在页面上,必然要使用到分页查询: 若不使用Ajax,而是用其他的方法,肯定是要刷新页面的,用户体检很不好, 所以最好使用Ajax的方法写分页查询: 1.先来找一张数据很多的表 ...
- ThinkPHP 整合Bootstrap Ajax分页
ThinkPHP Ajax分页代码 publicfunction index() { $where=array(); $name = I('name'); if(!empty($name)){ $wh ...
- MvcPager 概述 MvcPager 分页示例 — 标准Ajax分页 对SEO进行优化的ajax分页 (支持asp.net mvc)
该示例演示如何使用MvcPager最基本的Ajax分页模式. 使用AjaxHelper的Pager扩展方法来实现Ajax分页,使用Ajax分页模式时,必须至少指定MvcAjaxOptions的Upda ...
- yii下多条件多表组合查询以及自写ajax分页
多条件组合查询主要用到yii的CDbCriteria,这个类很多oem框架都有,非常好用. 前台表单 前台查询表单效果是这样的,多个条件组,每个组里放多个input,name为数组.当任何一个复选框被 ...
- ajax的分页查询(不刷新页面)
既然是分页查询,那么就要有张数据很多的表,可以让它进行分页显示,用普通的方法进行分页查询必然是要刷新页面的,这里要实现不刷新页面进行分页显示数据,就要用到ajax方式.进行编写代码 (1)先写个显示数 ...
随机推荐
- JavaSE笔记-注释
Annotation Annotation是一个接口,可以把Annotation当成一个修饰符 Annotation的定义 注解通过@interface定义 public @interface Tes ...
- JQuery Advanced
1.Jquery Utility <1> Type & Function & setTimeOut <!DOCTYPE html> <html lang= ...
- php页面编码设置
php的header来定义一个php页面为utf编码或GBK编码 php页面为utf编码 header("Content-type: text/html; charset=utf-8&quo ...
- WSL用xshell连接
编辑配置文件 sudo vim /etc/ssh/sshd_config Port 8022(因为 Windows 10 的 SSH 端口已经默认被占用,所以我换成了一个新的端口) (去掉前面的 #) ...
- upgrade openssl
01 OpenSSL version wiki:https://en.wikipedia.org/wiki/OpenSSL 02 Using TLS1.3 With OpenSSL https:// ...
- udp/tcp流程
udp: 1.创建套接字 socket 2.绑定本地ip/port bind 3.收发数据 sendto/recvfrom 4.关闭套接字 close tcp客户端: 1.创建套接字 socket 2 ...
- SpringBoot配置
多模块Maven项目 .gitignore文件 .idea *.iml targetout log tmp test 父模块pom文件 <?xml version="1.0" ...
- RIDE的下载及安装
1.本机配置 windows8.1 python3.6.5,已配置环境变量 2.安装RIDE前需要安装的依赖包(使用pip就可以直接安装) 首先必须有robotframework 例如:pip ins ...
- Python学习笔记七
面向对象编程 面向对象的特性如下: 类:具有相同属性和方法的一类事物,成为类. 对象:类的实例化后的结果,一个类可以实例化多个对象,每个对象也可以不同的属性. 封装:在类中对数据的赋值,类里面包含着类 ...
- 一起学Python——数据类型详解
和学习其他编程语言一样,首先要了解一门语言的数据类型. Python的数据类型有整型.浮点型.字符串.布尔型.日期时间类型.list列表.set集合.tuple元组.dict词典等. 1.整型 就是数 ...