use of org.nutz.dao.pager.Pager in project nutz by nutzam.
the class SimpleDaoTest method test_sql_pager.
@Test
public void test_sql_pager() {
dao.create(Pet.class, true);
for (int i = 0; i < 100; i++) {
dao.insert(Pet.class, Chain.make("name", "record" + i).add("nickName", "Time=" + System.currentTimeMillis()));
}
Pager pager = dao.createPager(5, 5);
pager.setRecordCount(dao.count(Pet.class));
Sql sql = Sqls.queryEntity("select * from t_pet");
sql.setEntity(dao.getEntity(Pet.class));
sql.setPager(pager);
dao.execute(sql);
List<Pet> pets = sql.getList(Pet.class);
assertNotNull(pets);
assertEquals(5, pets.size());
assertEquals("record20", pets.get(0).getName());
assertEquals("record21", pets.get(1).getName());
assertEquals("record22", pets.get(2).getName());
assertEquals("record23", pets.get(3).getName());
assertEquals("record24", pets.get(4).getName());
}
Aggregations