自己研究的高级查询公共分页包
1.PageBean的作用就是封装了分页所需要的信息
代码
package pagetools;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.struts.util.LabelValueBean;
public class PageBean {
private int page_current;
private int pagecount;
private HashMap last;
private HashMap pre;
private HashMap next;
private HashMap first;
private ArrayList page_list = new ArrayList();
public PageBean(int pageCount, int page_current, String mainType,
String subType) {
setFirst(new HashMap());
getFirst().put("page", 1);
getFirst().put("mainTypeId", mainType);
getFirst().put("subTypeId", subType);
setLast(new HashMap());
getLast().put("page", pageCount);
getLast().put("mainTypeId", mainType);
getLast().put("subTypeId", subType);
if (page_current == 1) {
setPre(new HashMap());
getPre().put("page", 1);
getPre().put("mainTypeId", mainType);
getPre().put("subTypeId", subType);
} else {
setPre(new HashMap());
getPre().put("page", page_current - 1);
getPre().put("mainTypeId", mainType);
getPre().put("subTypeId", subType);
}
if (page_current == pageCount) {
setNext(new HashMap());
getNext().put("page", pageCount);
getNext().put("mainTypeId", mainType);
getNext().put("subTypeId", subType);
} else {
setNext(new HashMap());
getNext().put("page", page_current + 1);
getNext().put("mainTypeId", mainType);
getNext().put("subTypeId", subType);
}
this.setPage_current(page_current);
this.pagecount =pageCount;
for (int i = 1; i <= pageCount; i++) {
page_list.add(new Integer(i));
}
}
public void setLast(HashMap last) {
this.last = last;
}
public HashMap getLast() {
return last;
}
public void setPre(HashMap pre) {
this.pre = pre;
}
public HashMap getPre() {
return pre;
}
public void setNext(HashMap next) {
this.next = next;
}
public HashMap getNext() {
return next;
}
public void setFirst(HashMap first) {
this.first = first;
}
public HashMap getFirst() {
return first;
}
public void setPage_current(int page_current) {
this.page_current = page_current;
}
public int getPage_current() {
return page_current;
}
public void setPage_list(ArrayList page_list) {
this.page_list = page_list;
}
public ArrayList getPage_list() {
return page_list;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
}
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.struts.util.LabelValueBean;
public class PageBean {
private int page_current;
private int pagecount;
private HashMap last;
private HashMap pre;
private HashMap next;
private HashMap first;
private ArrayList page_list = new ArrayList();
public PageBean(int pageCount, int page_current, String mainType,
String subType) {
setFirst(new HashMap());
getFirst().put("page", 1);
getFirst().put("mainTypeId", mainType);
getFirst().put("subTypeId", subType);
setLast(new HashMap());
getLast().put("page", pageCount);
getLast().put("mainTypeId", mainType);
getLast().put("subTypeId", subType);
if (page_current == 1) {
setPre(new HashMap());
getPre().put("page", 1);
getPre().put("mainTypeId", mainType);
getPre().put("subTypeId", subType);
} else {
setPre(new HashMap());
getPre().put("page", page_current - 1);
getPre().put("mainTypeId", mainType);
getPre().put("subTypeId", subType);
}
if (page_current == pageCount) {
setNext(new HashMap());
getNext().put("page", pageCount);
getNext().put("mainTypeId", mainType);
getNext().put("subTypeId", subType);
} else {
setNext(new HashMap());
getNext().put("page", page_current + 1);
getNext().put("mainTypeId", mainType);
getNext().put("subTypeId", subType);
}
this.setPage_current(page_current);
this.pagecount =pageCount;
for (int i = 1; i <= pageCount; i++) {
page_list.add(new Integer(i));
}
}
public void setLast(HashMap last) {
this.last = last;
}
public HashMap getLast() {
return last;
}
public void setPre(HashMap pre) {
this.pre = pre;
}
public HashMap getPre() {
return pre;
}
public void setNext(HashMap next) {
this.next = next;
}
public HashMap getNext() {
return next;
}
public void setFirst(HashMap first) {
this.first = first;
}
public HashMap getFirst() {
return first;
}
public void setPage_current(int page_current) {
this.page_current = page_current;
}
public int getPage_current() {
return page_current;
}
public void setPage_list(ArrayList page_list) {
this.page_list = page_list;
}
public ArrayList getPage_list() {
return page_list;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
}
2.PageDao主要封装需求和Sql
代码
package pagetools;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class PageDao extends HibernateDaoSupport {
public String select;// select查询子句
public String from;// from子句
public String where;// where子句
public String order;// order子句
public String typeFieldName;// 类别字段的名称
public String pageNum;// 当前要显示的页数
public int pageSize;// 一页显示多少条
public PageBean pagebean;
public String mainTypeId = "0";
public String subTypeId = "0";
public int rowCountInt = 0;
public ArrayList getPageListToGroupBy(){
ArrayList returnBookPageList = new ArrayList();
// //////取得表中记录数
// String rowCountSQL = "select count(*) " + from + " " + where;
// System.out.println("rowCountSQL============================"+rowCountSQL);
// List testList = this.getHibernateTemplate().getSessionFactory()
// .openSession().createQuery(rowCountSQL).list();
// rowCountInt = ((Long) testList.get(0)).intValue();
//
// System.out.println("记录数:" + rowCountInt);
// ///计算页数
int firstPos = (Integer.parseInt(pageNum) - 1) * pageSize;
System.out.println("firstPos=======" + firstPos);
String pageListSQL = select + " " + from + " " + where + " " + order;
System.out.println("hhhhhhhql====" + pageListSQL);
List resultList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(pageListSQL).list();
rowCountInt=resultList.size();
// ///计算页数
int pageCount = 0;
if (rowCountInt % pageSize == 0) {
pageCount = rowCountInt / pageSize;
} else {
pageCount = rowCountInt / pageSize + 1;
}
String a="abc";
a.substring(0, 3);
int end=0;
if(Integer.parseInt(pageNum)==pageCount){
end=rowCountInt % pageSize;
}else{
end=pageSize;
}
System.out.println("页数:" + pageCount);
System.out.println("当前页:" + pageNum);
resultList = resultList.subList(firstPos, firstPos+end);
// List pageList=new ArrayList();
// pageList.add(1)
//
// pageList.add(pageCount)
// System.out.println(resultList.size());
// if (mainTypeId.equals("0")) {
// createPageBean(pageCount, Integer.valueOf(pageNum), "all","all");
// } else {
// createPageBean(pageCount, Integer.valueOf(pageNum),
// mainTypeId,subTypeId);
//
// }
createPageBean(pageCount, Integer.valueOf(pageNum), mainTypeId,
subTypeId);
return (ArrayList) resultList;
}
public ArrayList getPageList() {
// ///返回book分页ArrayList
ArrayList returnBookPageList = new ArrayList();
// //////取得表中记录数
String rowCountSQL = "select count(*) " + from + " " + where;
System.out.println("rowCountSQL============================"+rowCountSQL);
List testList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(rowCountSQL).list();
rowCountInt = ((Long) testList.get(0)).intValue();
System.out.println("记录数:" + rowCountInt);
// ///计算页数
int pageCount = 0;
if (rowCountInt % pageSize == 0) {
pageCount = rowCountInt / pageSize;
} else {
pageCount = rowCountInt / pageSize + 1;
}
System.out.println("页数:" + pageCount);
System.out.println("当前页:" + pageNum);
int firstPos = (Integer.parseInt(pageNum) - 1) * pageSize;
System.out.println("firstPos=======" + firstPos);
String pageListSQL = select + " " + from + " " + where + " " + order;
System.out.println("hhhhhhhql====" + pageListSQL);
List resultList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(pageListSQL)
.setFirstResult(firstPos).setMaxResults(pageSize).list();
System.out.println(resultList.size());
createPageBean(pageCount, Integer.valueOf(pageNum), mainTypeId,
subTypeId);
// if (mainTypeId.equals("0")) {
// createPageBean(pageCount, Integer.valueOf(pageNum), "all","all");
// } else {
// createPageBean(pageCount, Integer.valueOf(pageNum),
// mainTypeId,subTypeId);
//
// }
return (ArrayList) resultList;
}
// public Map getTypeList(String id_typename_tablename) {
/* 定义存放类别表中类别的容器LinkedHashMap */
// LinkedHashMap type_list = new LinkedHashMap();
// // 从类别表中取出所有的数据,存入type_list_al中
// List type_list_al = this.getHibernateTemplate().getSessionFactory()
// .openSession().createQuery(id_typename_tablename).list();
// // 在type_list_al首先插入一个all类别
// // 即默认查询出所有的数据
// type_list.put("all", "all");
// // 将type_list_al变量中的数据转存到LinkedHashMap type_list中
// for (int i = 0; i < type_list_al.size(); i++) {
// type_list.put(((Object[]) type_list_al.get(i))[0],
// ((Object[]) type_list_al.get(i))[1]);
// }
// // 返回type_list列表
// return type_list;
//
// }
// public Map getTypeList(String id_typename_tablename) {
// // 定义存放类别表中类别的容器LinkedHashMap
// LinkedHashMap type_list = new LinkedHashMap();
// // 从类别表中取出所有的数据,存入type_list_al中
// List type_list_al = this.getHibernateTemplate().getSessionFactory()
// .openSession().createQuery(id_typename_tablename).list();
// // 在type_list_al首先插入一个all类别
// // 即默认查询出所有的数据
// type_list.put("all", "all");
// // 将type_list_al变量中的数据转存到LinkedHashMap type_list中
// for (int i = 0; i < type_list_al.size(); i++) {
// type_list.put(((Object[]) type_list_al.get(i))[0],
// ((Object[]) type_list_al.get(i))[1]);
// }
// // 返回type_list列表
// return type_list;
//
// }
// 创建JSP页面分页的导航类
// 参数:int page_count代表一共有多少页
// 参数:String type代表是什么类别
private PageBean createPageBean(int page_count, int page,
String mainTypeId, String subTypeId) {
if (mainTypeId.equals("all")) {
// 如果是查询出所有ALL类别时执行
return pagebean = new PageBean(page_count, page, "all", "all");
} else {
// 查询指定类别时执行
return pagebean = new PageBean(page_count, page, mainTypeId,
subTypeId);
}
}
public Map getNoviceQAPageList() {
// ///返回book分页ArrayList
ArrayList returnBookPageList = new ArrayList();
// //////取得表中记录数
String rowCountSQL = "select count(*) " + from + " " + where;
List testList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(rowCountSQL).list();
rowCountInt = ((Long) testList.get(0)).intValue();
System.out.println("记录数:" + rowCountInt);
// ///计算页数
int pageCount = 0;
if (rowCountInt % pageSize == 0) {
pageCount = rowCountInt / pageSize;
} else {
pageCount = rowCountInt / pageSize + 1;
}
// /////////////////////
System.out.println("页数:" + pageCount);
System.out.println("当前页:" + pageNum);
int firstPos = (Integer.parseInt(pageNum) - 1) * pageSize;
System.out.println("firstPos=======" + firstPos);
String pageListSQL = select + " " + from + " " + where + " " + order;
System.out.println("hhhhhhhql====" + pageListSQL);
List resultList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(pageListSQL)
.setFirstResult(firstPos).setMaxResults(pageSize).list();
Map showNoviceQA = new HashMap();
int questionId = 1;
ArrayList listBean = new ArrayList();
for (int i = 0; i < resultList.size(); i++) {
Object[] manageraObject = (Object[]) resultList.get(i);
System.out.println("11111111:::"
+ Integer.parseInt(String.valueOf(manageraObject[2])));
if (questionId != Integer.parseInt(String
.valueOf(manageraObject[2]))) {
showNoviceQA.put(new Integer(questionId), listBean);
listBean = new ArrayList();
questionId = Integer
.parseInt(String.valueOf(manageraObject[2]));
}
listBean.add(manageraObject);
}
showNoviceQA.put(new Integer(questionId), listBean);
createPageBean(pageCount, Integer.valueOf(pageNum), mainTypeId,
subTypeId);
// if (mainTypeId.equals("0")) {
// createPageBean(pageCount, Integer.valueOf(pageNum), "all","all");
// } else {
// createPageBean(pageCount, Integer.valueOf(pageNum),
// mainTypeId,subTypeId);
//
// }
return showNoviceQA;
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class PageDao extends HibernateDaoSupport {
public String select;// select查询子句
public String from;// from子句
public String where;// where子句
public String order;// order子句
public String typeFieldName;// 类别字段的名称
public String pageNum;// 当前要显示的页数
public int pageSize;// 一页显示多少条
public PageBean pagebean;
public String mainTypeId = "0";
public String subTypeId = "0";
public int rowCountInt = 0;
public ArrayList getPageListToGroupBy(){
ArrayList returnBookPageList = new ArrayList();
// //////取得表中记录数
// String rowCountSQL = "select count(*) " + from + " " + where;
// System.out.println("rowCountSQL============================"+rowCountSQL);
// List testList = this.getHibernateTemplate().getSessionFactory()
// .openSession().createQuery(rowCountSQL).list();
// rowCountInt = ((Long) testList.get(0)).intValue();
//
// System.out.println("记录数:" + rowCountInt);
// ///计算页数
int firstPos = (Integer.parseInt(pageNum) - 1) * pageSize;
System.out.println("firstPos=======" + firstPos);
String pageListSQL = select + " " + from + " " + where + " " + order;
System.out.println("hhhhhhhql====" + pageListSQL);
List resultList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(pageListSQL).list();
rowCountInt=resultList.size();
// ///计算页数
int pageCount = 0;
if (rowCountInt % pageSize == 0) {
pageCount = rowCountInt / pageSize;
} else {
pageCount = rowCountInt / pageSize + 1;
}
String a="abc";
a.substring(0, 3);
int end=0;
if(Integer.parseInt(pageNum)==pageCount){
end=rowCountInt % pageSize;
}else{
end=pageSize;
}
System.out.println("页数:" + pageCount);
System.out.println("当前页:" + pageNum);
resultList = resultList.subList(firstPos, firstPos+end);
// List pageList=new ArrayList();
// pageList.add(1)
//
// pageList.add(pageCount)
// System.out.println(resultList.size());
// if (mainTypeId.equals("0")) {
// createPageBean(pageCount, Integer.valueOf(pageNum), "all","all");
// } else {
// createPageBean(pageCount, Integer.valueOf(pageNum),
// mainTypeId,subTypeId);
//
// }
createPageBean(pageCount, Integer.valueOf(pageNum), mainTypeId,
subTypeId);
return (ArrayList) resultList;
}
public ArrayList getPageList() {
// ///返回book分页ArrayList
ArrayList returnBookPageList = new ArrayList();
// //////取得表中记录数
String rowCountSQL = "select count(*) " + from + " " + where;
System.out.println("rowCountSQL============================"+rowCountSQL);
List testList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(rowCountSQL).list();
rowCountInt = ((Long) testList.get(0)).intValue();
System.out.println("记录数:" + rowCountInt);
// ///计算页数
int pageCount = 0;
if (rowCountInt % pageSize == 0) {
pageCount = rowCountInt / pageSize;
} else {
pageCount = rowCountInt / pageSize + 1;
}
System.out.println("页数:" + pageCount);
System.out.println("当前页:" + pageNum);
int firstPos = (Integer.parseInt(pageNum) - 1) * pageSize;
System.out.println("firstPos=======" + firstPos);
String pageListSQL = select + " " + from + " " + where + " " + order;
System.out.println("hhhhhhhql====" + pageListSQL);
List resultList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(pageListSQL)
.setFirstResult(firstPos).setMaxResults(pageSize).list();
System.out.println(resultList.size());
createPageBean(pageCount, Integer.valueOf(pageNum), mainTypeId,
subTypeId);
// if (mainTypeId.equals("0")) {
// createPageBean(pageCount, Integer.valueOf(pageNum), "all","all");
// } else {
// createPageBean(pageCount, Integer.valueOf(pageNum),
// mainTypeId,subTypeId);
//
// }
return (ArrayList) resultList;
}
// public Map getTypeList(String id_typename_tablename) {
/* 定义存放类别表中类别的容器LinkedHashMap */
// LinkedHashMap type_list = new LinkedHashMap();
// // 从类别表中取出所有的数据,存入type_list_al中
// List type_list_al = this.getHibernateTemplate().getSessionFactory()
// .openSession().createQuery(id_typename_tablename).list();
// // 在type_list_al首先插入一个all类别
// // 即默认查询出所有的数据
// type_list.put("all", "all");
// // 将type_list_al变量中的数据转存到LinkedHashMap type_list中
// for (int i = 0; i < type_list_al.size(); i++) {
// type_list.put(((Object[]) type_list_al.get(i))[0],
// ((Object[]) type_list_al.get(i))[1]);
// }
// // 返回type_list列表
// return type_list;
//
// }
// public Map getTypeList(String id_typename_tablename) {
// // 定义存放类别表中类别的容器LinkedHashMap
// LinkedHashMap type_list = new LinkedHashMap();
// // 从类别表中取出所有的数据,存入type_list_al中
// List type_list_al = this.getHibernateTemplate().getSessionFactory()
// .openSession().createQuery(id_typename_tablename).list();
// // 在type_list_al首先插入一个all类别
// // 即默认查询出所有的数据
// type_list.put("all", "all");
// // 将type_list_al变量中的数据转存到LinkedHashMap type_list中
// for (int i = 0; i < type_list_al.size(); i++) {
// type_list.put(((Object[]) type_list_al.get(i))[0],
// ((Object[]) type_list_al.get(i))[1]);
// }
// // 返回type_list列表
// return type_list;
//
// }
// 创建JSP页面分页的导航类
// 参数:int page_count代表一共有多少页
// 参数:String type代表是什么类别
private PageBean createPageBean(int page_count, int page,
String mainTypeId, String subTypeId) {
if (mainTypeId.equals("all")) {
// 如果是查询出所有ALL类别时执行
return pagebean = new PageBean(page_count, page, "all", "all");
} else {
// 查询指定类别时执行
return pagebean = new PageBean(page_count, page, mainTypeId,
subTypeId);
}
}
public Map getNoviceQAPageList() {
// ///返回book分页ArrayList
ArrayList returnBookPageList = new ArrayList();
// //////取得表中记录数
String rowCountSQL = "select count(*) " + from + " " + where;
List testList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(rowCountSQL).list();
rowCountInt = ((Long) testList.get(0)).intValue();
System.out.println("记录数:" + rowCountInt);
// ///计算页数
int pageCount = 0;
if (rowCountInt % pageSize == 0) {
pageCount = rowCountInt / pageSize;
} else {
pageCount = rowCountInt / pageSize + 1;
}
// /////////////////////
System.out.println("页数:" + pageCount);
System.out.println("当前页:" + pageNum);
int firstPos = (Integer.parseInt(pageNum) - 1) * pageSize;
System.out.println("firstPos=======" + firstPos);
String pageListSQL = select + " " + from + " " + where + " " + order;
System.out.println("hhhhhhhql====" + pageListSQL);
List resultList = this.getHibernateTemplate().getSessionFactory()
.openSession().createQuery(pageListSQL)
.setFirstResult(firstPos).setMaxResults(pageSize).list();
Map showNoviceQA = new HashMap();
int questionId = 1;
ArrayList listBean = new ArrayList();
for (int i = 0; i < resultList.size(); i++) {
Object[] manageraObject = (Object[]) resultList.get(i);
System.out.println("11111111:::"
+ Integer.parseInt(String.valueOf(manageraObject[2])));
if (questionId != Integer.parseInt(String
.valueOf(manageraObject[2]))) {
showNoviceQA.put(new Integer(questionId), listBean);
listBean = new ArrayList();
questionId = Integer
.parseInt(String.valueOf(manageraObject[2]));
}
listBean.add(manageraObject);
}
showNoviceQA.put(new Integer(questionId), listBean);
createPageBean(pageCount, Integer.valueOf(pageNum), mainTypeId,
subTypeId);
// if (mainTypeId.equals("0")) {
// createPageBean(pageCount, Integer.valueOf(pageNum), "all","all");
// } else {
// createPageBean(pageCount, Integer.valueOf(pageNum),
// mainTypeId,subTypeId);
//
// }
return showNoviceQA;
}
}
3.给一个实际的例子,书的高级查询和分页
参数:page:当前页 acording:按照什么进行模糊查询 conditions:输入的条件 orderby:按照什么字段进行排序 rangking:升序还是降序
代码
public Map showBookinfoAll(String page, String mainTypeId,
String subTypeId, String according, String condition,
String orderby, String ranking) {
Map showBookinfoAll = new HashMap();
pageDAO.select = "select b.id, b.bookName," + "m.mainTypeName,"
+ "s.sontypename," + "b.bookPrice," + "b.bookCount,"
+ "b.discount," + "b.author," + "b.bookSales,"
+ "b.bookDateOflisting, "+"b.bookIsbn,"+" b.bookpublish";
pageDAO.from = " from Bookinfo as b,Bookmaintypename as m,Booksubtypename as s ";
pageDAO.where = " where b.subbooktypeid=s.id and m.id=s.mainid ";
if (!"".equals(according) && !"".equals(condition) && condition != null) {
pageDAO.where = pageDAO.where + " and b" + "." + according
+ " like '%" + condition + "%'";
}
if (!"0".equals(mainTypeId) && mainTypeId != null) {
pageDAO.where = pageDAO.where + " and b.mainbooktypeid ="
+ mainTypeId;
}
if (!"0".equals(subTypeId) && subTypeId != null) {
pageDAO.where = pageDAO.where + " and b.subbooktypeid ="
+ subTypeId;
}
pageDAO.order = " order by b.id desc";
if (!"0".equals(orderby) && orderby != null) {
pageDAO.order = "order by b." + orderby + " " + ranking;
}
if ("0".equals(orderby) || orderby == null && ranking != null
&& !"".equals(ranking)) {
pageDAO.order = "order by b.id " + ranking;
}
pageDAO.typeFieldName = " subbooktypeid";
pageDAO.pageNum = page;
pageDAO.pageSize = 14;
pageDAO.mainTypeId = mainTypeId;
pageDAO.subTypeId = subTypeId;
ArrayList pageList = pageDAO.getPageList();
showBookinfoAll.put("rowCountInt", String.valueOf(pageDAO.rowCountInt));
List chopList = new ArrayList();
String[] chopBookName = new String[pageList.size()];
for (int i = 0; i < pageList.size(); i++) {
Object[] object = (Object[]) pageList.get(i);
object[9] = new SimpleDateFormat("yyyy-MM-dd").format(object[9]);
chopBookName[i] = new Chop().chop(String.valueOf(object[1]), 12, "...");
}
chopList.add(chopBookName);
showBookinfoAll.put("chopList", chopList);
showBookinfoAll.put("pageList", pageList);
PageBean pageBean = pageDAO.pagebean;
showBookinfoAll.put("pageBean", pageBean);
List mainTypeList = allDAO.getMainBookTypeDAO().findAll();
showBookinfoAll.put("mainTypeList", mainTypeList);
if (!mainTypeId.equals("0")) {
List pageTypeList = allDAO.getSubBookTypeDAO().findByMainid(
Integer.parseInt(mainTypeId));
showBookinfoAll.put("pageTypeList", pageTypeList);
}
return showBookinfoAll;
}
String subTypeId, String according, String condition,
String orderby, String ranking) {
Map showBookinfoAll = new HashMap();
pageDAO.select = "select b.id, b.bookName," + "m.mainTypeName,"
+ "s.sontypename," + "b.bookPrice," + "b.bookCount,"
+ "b.discount," + "b.author," + "b.bookSales,"
+ "b.bookDateOflisting, "+"b.bookIsbn,"+" b.bookpublish";
pageDAO.from = " from Bookinfo as b,Bookmaintypename as m,Booksubtypename as s ";
pageDAO.where = " where b.subbooktypeid=s.id and m.id=s.mainid ";
if (!"".equals(according) && !"".equals(condition) && condition != null) {
pageDAO.where = pageDAO.where + " and b" + "." + according
+ " like '%" + condition + "%'";
}
if (!"0".equals(mainTypeId) && mainTypeId != null) {
pageDAO.where = pageDAO.where + " and b.mainbooktypeid ="
+ mainTypeId;
}
if (!"0".equals(subTypeId) && subTypeId != null) {
pageDAO.where = pageDAO.where + " and b.subbooktypeid ="
+ subTypeId;
}
pageDAO.order = " order by b.id desc";
if (!"0".equals(orderby) && orderby != null) {
pageDAO.order = "order by b." + orderby + " " + ranking;
}
if ("0".equals(orderby) || orderby == null && ranking != null
&& !"".equals(ranking)) {
pageDAO.order = "order by b.id " + ranking;
}
pageDAO.typeFieldName = " subbooktypeid";
pageDAO.pageNum = page;
pageDAO.pageSize = 14;
pageDAO.mainTypeId = mainTypeId;
pageDAO.subTypeId = subTypeId;
ArrayList pageList = pageDAO.getPageList();
showBookinfoAll.put("rowCountInt", String.valueOf(pageDAO.rowCountInt));
List chopList = new ArrayList();
String[] chopBookName = new String[pageList.size()];
for (int i = 0; i < pageList.size(); i++) {
Object[] object = (Object[]) pageList.get(i);
object[9] = new SimpleDateFormat("yyyy-MM-dd").format(object[9]);
chopBookName[i] = new Chop().chop(String.valueOf(object[1]), 12, "...");
}
chopList.add(chopBookName);
showBookinfoAll.put("chopList", chopList);
showBookinfoAll.put("pageList", pageList);
PageBean pageBean = pageDAO.pagebean;
showBookinfoAll.put("pageBean", pageBean);
List mainTypeList = allDAO.getMainBookTypeDAO().findAll();
showBookinfoAll.put("mainTypeList", mainTypeList);
if (!mainTypeId.equals("0")) {
List pageTypeList = allDAO.getSubBookTypeDAO().findByMainid(
Integer.parseInt(mainTypeId));
showBookinfoAll.put("pageTypeList", pageTypeList);
}
return showBookinfoAll;
}
附上效果图一张: