@wendal
在自定义sql中增加分页、自定义使用entity回调
Dao dao;
Ioc ioc;
try {
ioc = new NutIoc(new ComboIocLoader("*js", "config/"));
dao = ioc.get(Dao.class);
/** fetch/query方法 */
User userByName = dao.fetch(User.class, Cnd.where("login_name", "=", "admin"));
System.err.println(userByName);
/** 自定义sql entity回调 */
Sql sqlEntity = Sqls.create("SELECT t.* FROM GPM_USER t");
sqlEntity.setCallback(Sqls.callback.entities());
sqlEntity.setEntity(dao.getEntity(User.class));
dao.execute(sqlEntity);
List<NutMap> reEntity = (List<NutMap>) sqlEntity.getResult();
System.err.println(reEntity);
/** 自定义sql record回调 加分页*/
Sql sqlRecord = Sqls.create("SELECT t.* FROM GPM_USER t");
sqlRecord.setCallback(Sqls.callback.records());
Pager pager = dao.createPager(1, 1);
sqlRecord.setPager(pager);
sqlRecord.setEntity(dao.getEntity(User.class));
dao.execute(sqlRecord);
List<NutMap> reRecord = (List<NutMap>) sqlRecord.getResult();
System.err.println(reRecord);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
输出结果:
For example:> "SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM GPM_USER WHERE login_name='admin') T WHERE ROWNUM <= 1) WHERE RN > 0 "
User{id='null', loginName='null', password='null', name='null', organ='null', pwdErrorNumber=0, status='null', lastLoginTime=null}
20-09-17 10:48:28.916 DEBUG [main] SELECT t.* FROM GPM_USER t
[User{id='null', loginName='null', password='null', name='null', organ='null', pwdErrorNumber=0, status='null', lastLoginTime=null}, User{id='null', loginName='null', password='null', name='null', organ='null', pwdErrorNumber=0, status='null', lastLoginTime=null}, User{id='null', loginName='null', password='null', name='null', organ='null', pwdErrorNumber=0, status='null', lastLoginTime=null}]
20-09-17 10:48:28.920 DEBUG [main] SELECT * FROM (SELECT T.*, ROWNUM RN FROM (SELECT t.* FROM GPM_USER t) T WHERE ROWNUM <= 1) WHERE RN > 0
[{
"id": "c8a4b083df484807af6b9a6162c14e61",
"login_name": "admin",
"password": "d033e22ae348aeb5660fc2140aec35850c4da997",
"name": null,
"organ": "1700000000",
"status": "1",
"pwd_error_number": 0,
"last_login_time": "2020-08-25 19:41:25",
"rn": 1
}]
自定义sql中的record回调增加分页查询,结果仍然是正确的。