社区
Ajax
帖子详情
java中pageInfo分页带条件查询+查询条件的回显
z940136637
2019-04-22 09:34:19
急着做项目,要用pageInfo的异步分页条件查询,有没有大佬可以给个页面和Controller的代码看看
...全文
1123
1
打赏
收藏
java中pageInfo分页带条件查询+查询条件的回显
急着做项目,要用pageInfo的异步分页条件查询,有没有大佬可以给个页面和Controller的代码看看
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
usecf
2019-04-22
打赏
举报
回复
$("#deviceinfo_start").datagrid({
title: '设备管理',
checkOnSelect: false,
remoteSort:false,
pagination:true,
pageSize:20,
pageNumber:1,
toolbar: '#deviceinfo_toolbar',
url: 'requeryDeviceData',
loadMsg:'加载中...',
height: "300px",
striped: true, //交替行换色
fit: true,
columns: [[
{title: '',field: 'IndexId', width: 80, checkbox: true,},
{field:'deviceNo',title:'设备编号',width:100,sortable:true,sorter:sortItem},
{field:'deviceMac',title:'设备MAC',width:100},
{field:'deviceImei',title:'设备IMEI',width:100},
{field:'deviceSn',title:'设备SN',width:100},
{field:'deviceModel',title:'设备型号',width:100},
{field:'deviceVender',title:'设备制造商',width:100},
{field:'deviceHardVer',title:'设备硬件版本',width:100},
{field:'deviceSoftVer',title:'设备软件版本',width:100},
{field:'deviceUpdateTime',title:'更新时间',width:100,sortable:true,sorter:sortItem},
{field:'deviceState',title:'设备状态',width:100,sortable:true,sorter:sortItem},
{field:'deviceReMark1',title:'预留字段1',width:100},
{field:'deviceReMark2',title:'预留字段2',width:100}
]]
});
采用的是layui框架
controller
@RequestMapping(value = "/requeryDeviceData")
@ResponseBody
public String requeryDeviceData(HttpServletRequest request, HttpServletResponse response, HttpSession httpSession){
System.out.print("enter requeryDeviceData");
String json = "";
int page = Integer.parseInt(request.getParameter("page"));
int rows = Integer.parseInt(request.getParameter("rows"));
String searchFlag = request.getParameter("searchFlag");
String searchKey = request.getParameter("searchKey");
if(null != searchFlag && 0 == searchFlag.compareTo("1"))
{
List<DeviceManagerTable> dmList = null;
HttpRequestUtil http = new HttpRequestUtil();
try
{
dmList = deviceManagerService.queryUserByName(searchKey);
JSONArray dmArray = JSONArray.fromObject(dmList);
json = String.format("{\"result\":\"success\",\"total\":%d,\"rows\":%s}", dmList.size(),dmArray.toString());
}
catch(Exception e)
{
json = "{\"result\":\"fail\",\"message\":\"01\"}";
e.printStackTrace();
}
finally
{
http.httpResponse(response, json);
}
}
else if((0 != page && 0 != rows) && (null ==searchFlag))
{
List<DeviceManagerTable> dmList = new ArrayList<DeviceManagerTable>();
List<DeviceManagerTable> dmListTotal = new ArrayList<DeviceManagerTable>();
HttpRequestUtil http = new HttpRequestUtil();
try
{
dmListTotal = deviceManagerService.requeryDeviceData();
dmList = deviceManagerService.getPageList(page,rows);
JSONArray dmArray = JSONArray.fromObject(dmList);
json = String.format("{\"result\":\"success\",\"total\":%d,\"rows\":%s}", dmListTotal.size(),dmArray.toString());
}
catch(Exception e)
{
json = "{\"result\":\"fail\",\"message\":\"01\"}";
e.printStackTrace();
}
finally
{
http.httpResponse(response, json);
}
}
return json;
}
分页
查询
--
Java
项目实战篇
分页
查询
,想必大家在看到这篇文章时也已了解什么是
分页
查询
。这个功能也是开发过程
中
很常见的一个功能模块知识点。在显示到页面用户看到的也大多数都是
分页
查询
展示出来的数据,数据多时还会有一个搜索框,用户在搜索框内输入完信息后,后台就会使用模糊
查询
将用户搜索的信息相关的内容展示到页面给用户。这个过程离不开
分页
查询
。 然而
分页
查询
自己写源码是一个非常复杂的过程。这里Mybatis-Plus就为我们提供了
分页
查询
的功能,我们只需要按照Mybatis-Plus里封装好的基础上去编写业务逻辑代码即可(会使用即可),不用去
纳税服务系统【
条件
查询
数据
回显
、
分页
】
前言前面我们已经完成了
条件
查询
的功能,可以根据用户给出的
条件
进行
查询
数据。但是呢,还是有一些小毛病的。我们来看看:当我们
查询
数据时候,对
查询
出来的数据进行操作。操作完毕后,它回到的不是我们
查询
后的数据,而是我们的初始化数据。这明显是不合适的,当用户操作完后,我们应该返回的还是
条件
查询
出来的数据。还有一点的就是:我们的
分页
还没写……因此,本文主要解决这两个问题。数据
回显
首先,我们来分析一下为什么我们操
Page
Info
-
分页
total与在库数据量不符
在controller
中
使用
Page
Helper.start
Page
分页
后,调用service层方法
查询
并处理了list。
分页
查询
后,
page
Info
获取到的total为size值(
回显
为10条),与实际总条数不符(实际为67条)。2.但因业务需要在返回之前对集合做了处理:将
page
类型的对象转化成了List
类型。3.再将新的集合(此时已是List
类型)使用
分页
转化工具转化无效。1.从数据库
中
查出来的对象是
page
类型的。
Java
处理List集合数据进行
分页
展示
System.out.println("总页数"+((list.size()/
page
Size)+1));System.out.println("每页个数"+query
Page
Info
.get
Page
Size());System.out.println("当前页"+query
Page
Info
.get
Page
Num());System.out.println("总条数"+list.size());System.out.println("每页个数"+
page
Size);...
Ajax
52,787
社区成员
25,335
社区内容
发帖
与我相关
我的任务
Ajax
Web 开发 Ajax
复制链接
扫一扫
分享
社区描述
Web 开发 Ajax
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章