NutzCN Logo
问答 使用Pagination分页时,偶尔会出现limit拼接多次,各位大神这是什么情况?
发布于 1965天前 作者 wx_jp6ghmlqmnf4ugvarroq 1735 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

例如:
public Pagination completeTransportations(String id, Integer pageNumber) {
String sqls = "SELECT t.id AS id,g.is_tax , t.trade_no AS trade_no,t.num AS tranWeight, g.receipt_name AS receipt_name,g.receipt_phone AS receipt_phone,g.weight AS weight, g.load_weight AS load_weight, g.weight_type AS weight_type,t.status AS status FROM transportation AS t JOIN goods AS g ON t.goods_id = g.id WHERE ( t.status IN (4, 5, 6, 7) OR (t.status=8 AND t.is_abnormal = 0 ))AND t.is_del = 0 ";
Pagination pagination = new Pagination();
if (Strings.isNotBlank(id)) {
String q = " AND t.driver_id = @id ORDER BY t.create_time DESC ";
sqls = sqls + q;
}
sql = Sqls.create(sqls);
if (Strings.isNotBlank(id)) {
sql.params().set("id", id);
}
Integer pageSize = 20;
pagination = listPage(pageNumber, pageSize, sql);
return pagination;
}
偶尔出现的sql语句就是:SELECT t.id AS id,g.is_tax , t.trade_no AS trade_no,t.num AS tranWeight, g.receipt_name AS receipt_name,g.receipt_phone AS receipt_phone,g.weight AS weight, g.load_weight AS load_weight, g.weight_type AS weight_type,t.status AS status FROM transportation AS t JOIN goods AS g ON t.goods_id = g.id WHERE ( t.status IN (4, 5, 6, 7) OR (t.status=8 AND t.is_abnormal = 0 ))AND t.is_del = 0 limit 10,10 limit 10,10
limit输出2次,甚至是3次,造成执行异常。
请问各位大神,你们有遇见过吗?

5 回复

发帖提示都不看了...

listPage里面写了啥

我看发帖提示了,并且贴出代码了。不清楚大神你指的是什么?

public Pagination listPage(Integer pageNumber, int pageSize, Sql sql) {
        pageNumber = getPageNumber(pageNumber);
        pageSize = getPageSize(pageSize);
        Pager pager = this.dao().createPager(pageNumber, pageSize);
        pager.setRecordCount((int) Daos.queryCount(this.dao(), sql));// 记录数需手动设置
        sql.setPager(pager);
        sql.setCallback(Sqls.callback.records());
        this.dao().execute(sql);
        return new Pagination(pageNumber, pageSize, pager.getRecordCount(), sql.getList(Record.class));
    }

这个是listPage里的内容

嗯,群里说了, sql变量的作用域不对

懂了 多线程调用同一个实例

添加回复
请先登陆
回到顶部