Search in sources :

Example 1 with PageRow

use of com.blade.jdbc.model.PageRow in project tale by otale.

the class ContentsServiceImpl method getArticles.

@Override
public Paginator<Contents> getArticles(Integer mid, int page, int limit) {
    String countSql = "select count(0) from t_contents a left join t_relationships b on a.cid = b.cid " + "where b.mid = ? and a.status = 'publish' and a.type = 'post'";
    int total = activeRecord.one(Integer.class, countSql, mid);
    PageRow pageRow = new PageRow(page, limit);
    Paginator<Contents> paginator = new Paginator<>(total, pageRow.getPage(), pageRow.getLimit());
    String sql = "select a.* from t_contents a left join t_relationships b on a.cid = b.cid " + "where b.mid = ? and a.status = 'publish' and a.type = 'post' order by a.created desc limit " + pageRow.getOffSet() + "," + limit;
    List<Contents> list = activeRecord.list(Contents.class, sql, mid);
    if (null != list) {
        paginator.setList(list);
    }
    return paginator;
}
Also used : Contents(com.tale.model.Contents) PageRow(com.blade.jdbc.model.PageRow) Paginator(com.blade.jdbc.model.Paginator)

Aggregations

PageRow (com.blade.jdbc.model.PageRow)1 Paginator (com.blade.jdbc.model.Paginator)1 Contents (com.tale.model.Contents)1