dao.query()可以指定查那些需要的字段吗
4 回复
自定义SQL
public TableDataInfo selectTableList(String tableName, String tableComment, int pageNumber, int pageSize, String orderByColumn, String isAsc) {
String sqlstr = "select table_name, table_comment, create_time, update_time from information_schema.tables " +
"where table_comment <> '' and table_schema = (select database()) ";
if (Strings.isNotBlank(tableName)) {
sqlstr += "and table_name like @tableName";
}
if (Strings.isNotBlank(tableComment)) {
sqlstr += "and table_comment like @tableComment";
}
if (Strings.isNotBlank(orderByColumn) && Strings.isNotBlank(isAsc)) {
sqlstr += " order by " + GenUtils.javaToTable(orderByColumn) + " " + isAsc;
}
Sql sql = Sqls.create(sqlstr);
sql.params().set("tableName", "%" + tableName + "%");
sql.params().set("tableComment", "%" + tableComment + "%");
sql.setCallback(Sqls.callback.entities());
Entity<TableInfo> entity = dao.getEntity(TableInfo.class);
Pager pager = dao.createPager(pageNumber, pageSize);
//记录数需手动设置
pager.setRecordCount((int) Daos.queryCount(dao, sql));
sql.setPager(pager);
sql.setEntity(entity).setCondition(Cnd.wrap(sqlstr));
dao.execute(sql);
// return sql.getList(TableInfo.class);
return new TableDataInfo(sql.getList(TableInfo.class), pager.getRecordCount());
}
添加回复
请先登陆