nutz 結合QueryResult,Record 自定義分頁查詢,不構建pojo 整合
阿新 • • 發佈:2018-03-14
new ack long exceptio tlist call poj return .class
public QueryResult getHistoryIncome(int d, int curPage)
throws Exception {
/**sql**/
Sql sql = Sqls.create("select a,b,c from A where d=@d ")
.setParam("d", d);
/**查詢個數**/
Sql sqlcount = Sqls.create("SELECT count(*)as number FROM mytask t WHERE d = @d")
.setParam("d", d);
sqlcount.setCallback(Sqls.callback.entity());
sqlcount.setEntity(dao.getEntity(Record.class));
dao.execute(sqlcount);
Record countRecord=(Record) sqlcount.getResult();
long count=(long) countRecord.get("number");
if(curPage==0){
curPage=1;
}
Pager pager=dao.createPager(curPage, 10);
pager.setRecordCount((int) count);
sql.setPager(pager);
/**列表**/
sql.setCallback(Sqls.callback.entities());
Entity<Record> entity = dao.getEntity(Record.class);
sql.setEntity(entity);
dao.execute(sql);
return new QueryResult(sql.getList(Record.class), pager);
}
取出列表信息:
QueryResult對象.getList(Record.class);
取出分頁信息
QueryResult對象.getPager();
nutz 結合QueryResult,Record 自定義分頁查詢,不構建pojo 整合