public List getList(String startTime, String endTime, String mc, Pager pager)
{
String where = " ";
where = where + " and " + TypeChange.DateBetweenSql("a.riQi", startTime, endTime);
if (!TypeChange.toNotNullDao(mc).equals(""))
{
where = where + " and a.mingCheng like '%" + TypeChange.toNotNullDao(mc) + "%'";
}
return this.findAll(where, pager);
}
findAll:
private List<Test> findAll(String where, Pager pager)
{
String hSql = " From Test a where 1=1 " + where + " order by id ";
pager.setRowCount(getAllRowCount(hSql));
Session sess = this.getSessionFactory().openSession();
try
{
Query query = sess.createQuery(hSql);
query.setFirstResult(pager.getFirstResult());
query.setMaxResults(pager.getPageSize());
return query.list();
}
finally
{
sess.close();
}
}
public List getList(String startTime, String endTime, String mc, Pager pager)
{
String where = " "; //初始條件為空
where = where + " and " + TypeChange.DateBetweenSql("a.riQi", startTime, endTime); // 把開始結束時間作為條件
if (!TypeChange.toNotNullDao(mc).equals(""))
{
where = where + " and a.mingCheng like '%" + TypeChange.toNotNullDao(mc) + "%'"; // 關鍵字模糊查詢 like %關鍵字%,就是包含它的文本視作匹配。
}
return this.findAll(where, pager);
}
findAll:
private List findAll(String where, Pager pager) //分頁查詢
{
String hSql = " From Test a where 1=1 " + where + " order by id "; // 按照條件來匹配,加上1=1是防止where為空
pager.setRowCount(getAllRowCount(hSql)); // 每頁的數量
Session sess = this.getSessionFactory().openSession();
try
{
Query query = sess.createQuery(hSql); //構造sql
query.setFirstResult(pager.getFirstResult());
query.setMaxResults(pager.getPageSize());
return query.list();
}
finally
{
sess.close();
}
}