StringBuilder selectSql = new StringBuilder();
selectSql.append("SELECT ******** ");
selectSql.append(" ORDER BY beforeTime DESC ");
StringBuilder countSql = new StringBuilder();
countSql.append("SELECT COUNT(0) FROM (").append(selectSql).append(") AS result");
Integer count = daoTemplate.queryForInt(countSql.toString(), null);
Sql sql = Sqls.create(selectSql.toString());
Pager pager = this.daoTemplate.createPager(pageNo, pageSize);
sql.setPager(pager);
//自定义实体对象MyRowMapper
Entity<MyRowMapper> entity = new NutEntity(MyRowMapper.class);
sql.setEntity(entity);
//设置回调
sql.setCallback(Sqls.callback.records());
this.daoTemplate.execute(sql);
List<MyRowMapper> list = sql.getList(MyRowMapper.class);
return list;
NutzDao多表关联分页查询
该段代码展示了如何使用StringBuilder构建SQL查询语句,包括选择性地获取数据并进行排序,计算记录总数,以及利用分页查询。通过daoTemplate执行SQL,使用自定义的MyRowMapper实体映射结果,并获取数据列表。
摘要由CSDN通过智能技术生成