easyui分页时,总页数出错
错误出现
MyBatis用easyui写后台分页代码时,出现翻页后显示总页数错误


代码如下
可能原因在于后台mappers.xml里的sql语句错误
<select id="getProductTotal" parameterType="Map" resultType="Long">
select count(*) from t_product
<where>
<if test="name!=null and name!=''">
and name like #{name}
</if>
</where>
<if test="start!=null and size!=null">
limit #{start},#{size}
</if>
</select>
去掉limit语句
<select id="getProductTotal" parameterType="Map" resultType="Long">
select count(*) from t_product
<where>
<if test="name!=null and name!=''">
and name like #{name}
</if>
</where>
</select>
controller的代码如下
@RequestMapping("/list")
public String list(@RequestParam(value="page",required=false)String page,@RequestParam(value="rows",required=false)String rows,Product product,HttpServletResponse response)throws Exception{
PageBean pageBean = new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
Map<String,Object> map = new HashMap<String,Object>();
map.put("name", StringUtil.formatLike(product.getName()));
map.put("start", pageBean.getStart());
map.put("size", pageBean.getPageSize());
List<Product> productList = productService.productList(map);
Long total = productService.getProductTotal(map);
JSONObject result=new JSONObject();
JsonConfig jsonConfig=new JsonConfig();
jsonConfig.setExcludes(new String[]{"orderProductList"});
jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd"));
jsonConfig.registerJsonValueProcessor(ProductBigType.class,new ObjectJsonValueProcessor(new String[]{"id","name"}, ProductBigType.class));
jsonConfig.registerJsonValueProcessor(ProductSmallType.class,new ObjectJsonValueProcessor(new String[]{"id","name"}, ProductSmallType.class));
JSONArray jsonArray=JSONArray.fromObject(productList,jsonConfig);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(response, result);
return null;
}
改变后
因为前台easyui传入的数据start在变,变化前的sql语句为
SELECT COUNT(*) FROM t_product LIMIT 0,10
可以查询出总记录数
但start变化后
SELECT COUNT(*) FROM t_user LIMIT 10,10
无法查询出总记录数,所以导致出错!
easyui分页时,总页数出错的更多相关文章
- GridView自带分页 1总页数 首页 下一页 上一页 尾页 X 页 go 实现方法 .
在前台GRIDVIEW中添加如下代码 <PagerTemplate> <table> <tr> <td style="text-align: rig ...
- mvc自定义分页(加页数的)(转)
1.引言 在MVC开发中我们经常会对数据进行分页的展示.通过分页我们可以从服务端获取指定的数据来进行展示.这样既节约了数据库查询的时间也节约了网络传输的数据量.在MVC开发中使用的比较多的应该是MVC ...
- C# 返回分页查询的总页数
/// <summary> /// 返回分页查询操作的的总页数 /// </summary> /// <param name="count">总 ...
- word中怎样设置页码包含总页数
一个同事做毕业论文,论文是Word格式,1-2页是封面和目录,不需要页码,第3-10页是论文内容,需要从第1页开始显示,并显示论文内容的总页数8 页.具体为页脚处显示“第*页共*页”.他让我帮忙设置一 ...
- word2010页脚页码的总页数修改方法
3很多时候做WORD文档时,首页和尾页通常是做为封面与封底的是不做页码统计的. 这时候就需要总页面上减去首页和尾页的数量.以下为修改总页数方法 1.打开WORD文档设置页眉页脚,页脚设置页码, 2.设 ...
- 使用CyclicBarrier+线程池,按总页数分批次开多线程执行逻辑
通过CyclicBarrier+线程池的方式,同步的方式分页分批次并发高效处理逻辑,将总页数分成多个批次并发执行每页逻辑,每个批次处理DO_MAX_SIZE个页,每个批次等待DO_MAX_SIZE个页 ...
- js计算总页数
前端js取余是a%b 取除数parseInt(a / b) /** * 总页数@param(总条数,每页总条数) */ function pageTotal(rowCount, pageSize) { ...
- sql计算总页数
1 计算总页数方法: public int getTotalCount() { Statement stmt = null; //提交SQL语句对象stmt Resu ...
- js 计算总页数的最高效方式
js 计算总页数的最高效方式 /** * [getTotalPageNum 获取页码总数] * @param {[type]} totalRecord [总记录] * @param {[type]} ...
随机推荐
- Lucene原理与代码分析
http://www.cnblogs.com/forfuture1978/category/300665.html
- React项目搭建及依赖安装
一.前提 首先保证node.js已安装完成... 安装完成后,打开cmd命令行,输入 node -v 和 npm -v 来查看版本号,如果显示则安装完成. 二.安装react脚手架 在cmd命令行中输 ...
- OpenWrt 路由器如何让 lan 口主机获得 ipv6 网络访问 -- 知乎
本文转自知乎: OpenWrt 路由器如何让 lan 口主机获得 ipv6 网络访问? - mistforest的回答 - 知乎https://www.zhihu.com/question/29667 ...
- windows python MySQLdb 安装配置
一.环境 系统:windows10/7/8 软件: 1.python2.7.XX(https://www.python.org/downloads/或者https://www.python.org/f ...
- python基础知识14-正则表达式
1.正则表达式 正则可以代替其他任何工具,但是其他工具不能完全代替正则. 1.匹配或提取字符串的工具,基于所有语言之上的工具. 正则表达式所面向的问题 判断一个字符串是否匹配给定的格式,如判断用户注册 ...
- 剑指offer重构二叉树 给出二叉树的前序和后序重构二叉树
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树. 假设输入的前序遍历和中序遍历的结果中都不含重复的数字. 例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4, ...
- Oracle联合主键
转https://www.cnblogs.com/king-xg/p/6721272.html alter table tablename add constraint unionkeyname pr ...
- gnu make规则记录
1. $(shell CMD) 名称: 执行 shell 命令函数 功能: 在新的 shell 中执行 CMD 命令 返回值: CMD 在 shell 中执行的结果 例如:PLATFORM=$(she ...
- CodeForces 699C - Vacations
题目链接:http://codeforces.com/problemset/problem/699/C C. Vacations time limit per test1 second memory ...
- Ubuntu 16.04 LTS上git提交出现警告Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts. 的解决方法
问题: Ubuntu 16.04 LTS执行 git pull时总会出现以下警告: Warning: Permanently added 'github.com,52.74.223.119' (RSA ...