Pager<Record> pager = new Pager<Record>(PAGESIZE, page);
String searchKey = String.format("%%%s%%", key);
Condition cnd = Cnd.NEW();
Sql sql = dao.sqls().create("find.equipment.list");
Sql sqlcount = dao.sqls().create("find.equipment.count");
cnd = Cnd.where(null).and("c.cb_name", "like", searchKey).or("c.cb_macid", "like", searchKey).or("c.cb_group", "like", searchKey);
sql.setCondition(cnd);
sqlcount.setCondition(cnd);
sql.params().set("pageStart", (page - 1) * PAGESIZE);
sql.params().set("pageSize", PAGESIZE);
pager.setEntities(SqlActuator.runReport(sql, dao));
pager.setCount(SqlActuator.runUnq(sqlcount, dao));
return pager;
sql语句:
/*find.equipment.list*/
SELECT
c.id AS id,
r.r_name AS regionName,
c.cb_name AS cbName,
c.cb_macid AS cbMacId,
c.cb_group AS cbGroup,
c.cb_enable AS cbEnable
FROM
sdy_cbdevice c
LEFT JOIN brt_region r ON r.id = c.r_id
$condition limit @pageStart,@pageSize;
/*find.equipment.count*/
SELECT
count(*)
FROM
sdy_cbdevice c
$condition
运行结果:
entities :[{
id :2,
regionname :"陕西历史博物馆",
cbname :"1212wqqw",
cbmacid :"qwqw1212",
cbgroup :"qwqwq",
cbenable :true
}, {
id :1,
regionname :"法门寺博物馆",
cbname :"nba",
cbmacid :"12wedrf",
cbgroup :"1212we",
cbenable :true
}],