错误出现

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分页时,总页数出错的更多相关文章

  1. GridView自带分页 1总页数 首页 下一页 上一页 尾页 X 页 go 实现方法 .

    在前台GRIDVIEW中添加如下代码 <PagerTemplate> <table> <tr> <td style="text-align: rig ...

  2. mvc自定义分页(加页数的)(转)

    1.引言 在MVC开发中我们经常会对数据进行分页的展示.通过分页我们可以从服务端获取指定的数据来进行展示.这样既节约了数据库查询的时间也节约了网络传输的数据量.在MVC开发中使用的比较多的应该是MVC ...

  3. C# 返回分页查询的总页数

    /// <summary> /// 返回分页查询操作的的总页数 /// </summary> /// <param name="count">总 ...

  4. word中怎样设置页码包含总页数

    一个同事做毕业论文,论文是Word格式,1-2页是封面和目录,不需要页码,第3-10页是论文内容,需要从第1页开始显示,并显示论文内容的总页数8 页.具体为页脚处显示“第*页共*页”.他让我帮忙设置一 ...

  5. word2010页脚页码的总页数修改方法

    3很多时候做WORD文档时,首页和尾页通常是做为封面与封底的是不做页码统计的. 这时候就需要总页面上减去首页和尾页的数量.以下为修改总页数方法 1.打开WORD文档设置页眉页脚,页脚设置页码, 2.设 ...

  6. 使用CyclicBarrier+线程池,按总页数分批次开多线程执行逻辑

    通过CyclicBarrier+线程池的方式,同步的方式分页分批次并发高效处理逻辑,将总页数分成多个批次并发执行每页逻辑,每个批次处理DO_MAX_SIZE个页,每个批次等待DO_MAX_SIZE个页 ...

  7. js计算总页数

    前端js取余是a%b 取除数parseInt(a / b) /** * 总页数@param(总条数,每页总条数) */ function pageTotal(rowCount, pageSize) { ...

  8. sql计算总页数

    1 计算总页数方法: public int getTotalCount() {        Statement stmt = null;    //提交SQL语句对象stmt        Resu ...

  9. js 计算总页数的最高效方式

    js 计算总页数的最高效方式 /** * [getTotalPageNum 获取页码总数] * @param {[type]} totalRecord [总记录] * @param {[type]} ...

随机推荐

  1. CSS3的border-image

    border-image:none|image-url|number|percentage|stretch,repeat,round 参数: none:默认,无背景图片 url:地址,可以为绝对,也可 ...

  2. Python9-继承2-day25(大年初二)

    继承:什么是什么关系组合:什么有什么关系单继承 先抽象再继承,几个类直接的相同代码抽象出来,成为父类 子类自己没有的名字可以使用父类的方法和属性 如果子类自己有,一定先用自己的 在类中使用self的时 ...

  3. Linux 权限设置和 SUID, SGID 以及粘滞位sticky bit

    suid是指在执行suid程序的过程中,去访问其他文件时拥有suid程序属主的权限,而不是指对suid程序本身拥有suid程序属主的权限! 一. Linux 文件权限的表示方法 文件权限用 12 个二 ...

  4. numpy array_split()

    numpy.array_split(ary, indices_or_sections, axis=0)[source] Split an array into multiple sub-arrays. ...

  5. [uiautomator篇] 找父亲节点和其他兄弟节点

    https://testerhome.com/topics/1250 Appium [已解决] UiSelector 如何根据节点定位到父节点 / 兄弟节点? liqing380 · 发布于 2014 ...

  6. POJ 2092 Grandpa is Famous

    Grandpa is Famous Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 7153   Accepted: 3624 ...

  7. HackerRank# Bricks Game

    原题地址 DP很简单,懒得压缩空间了,反正都能过 #include <cmath> #include <cstdio> #include <vector> #inc ...

  8. BZOJ 4503 两个串 ——FFT

    [题目分析] 定义两个字符之间的距离为 (ai-bi)^2*ai*bi 如果能够匹配,从i到i+m的位置的和一定为0 但这和暴力没有什么区别. 发现把b字符串反过来就可以卷积用FFT了. 听说KMP+ ...

  9. 【FFT求卷积】Problem D. Duel

    [AC] #include <stdio.h> #include <iostream> #include <string.h> #include <algor ...

  10. log4j详细配置解析

    出自:http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记录 ...