快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

澳门新葡亰集团_龟发之家论坛



一、页面添加

http://displaytag.sf.net" prefix="display"%>

二、 PageSplit

package util;

import java.util.List;

import org.displaytag.pagination.PaginatedList;

import org.displaytag.properties.SortOrderEnum;

public class PageSplit implements PaginatedList{

private List list;

private int pageNumber = 1;

private int objectsPerPage = 20;

private int fullListSize = 0;

private String sortCriterion;

private SortOrderEnum sortDirection;

private String searchId;

public List getList() {

return list;

}

public void setList(List list) {

this.list = list;

}

public int getPag澳门新葡亰集团eNumber() {

return pageNumber;

}

public void setPageNumber(int pageNumber) {

this.pageNumber = pageNumber;

}

public int getObjectsPerPage() {

return objectsPerPage;

}

public void setObjectsPerPage(int objectsPerPage) {

this.objectsPerPage = objectsPerPage;

}

public int getFullListSize() {

return fullListSize;

}

public void setFullListSize(int fullListSize) {

this.fullListSize = fullListSize;

}

public String澳门新葡亰集团 getSortCriterion() {

return sortCriterion;

}

public void setSortCriterion(String sortCriterion) {

this.sortCriterion = sortCriterion;

}

public SortOrderEnum getSortDirection() {

return sortDirection;

}

public void setSortDirection(SortOrderEnum sortDirection) {

this.sortDirection = sortDirection;

}

public String getSearchId() {

return searchId;

}

public void setSearchId(String searchId) {

this.searchId = searchId;

}

}

三、GetPageList

package util;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.displaytag.pagination.PaginatedList;

import org.displaytag.properties.SortOrderEnum;

public class GetPageList {

private IPageSplitSrv srv;

private HttpServletRequest request;

private Object param = null;

public GetPageList(HttpServletRequest request,IPageSplitSrv srv){

this.srv = srv;

this.request = request;

}

@SuppressWarnings("unchecked")

public PaginatedList getPageList()

{

int pageSize;

if (request.getParameter("pageSize") != null

&& !"".equals(request.getParameter("pageSize"))) {

pa澳门新葡亰集团geSize = Integer.parseInt(request.getParameter("pageSize"));

} else {

pageSize =16;

}

int page = 1;

if (request.getParameter("page") != null

&& !"".equals(request.getParameter("page"))) {

page = Integer.parseInt(request.getParameter("page"));

} else {

p澳门新葡亰集团age = 1;

}

String sortCriterion = request.getParameter("sort");

String sortDirection = request.getParameter("dir");

Map map = new HashMap();

map.put("sorder", sortCriterion);

map.put("sdir", sortDirection);

int fromIndex = (page - 1) * pageSize;

//int toIndex = fromIndex + pageSize;

int toIndex = pageSize;

// 得到每次查询的总记录数

int ListSize =srv.findSize(this.getParam());;

// 此页要显示的list数据

List list = null;

if (ListSize > 0) {

if(null!=this.getParam()){

list = srv.search(this.getParam(), map, fromIndex, toIndex);

}else{

list = srv.search(map,fromIndex, toIndex);//DAO中实现

}

} else {

list = null;

}

PaginatedList pageList = new PageSplit();

((PageSplit) pageList).setPageNumber(page);

((PageSplit) pageList).setSortCriterion(sortCriterion);

if(null!=sortDirection){

SortOrderEnum sortOrderEnum = sortDirection.equals("asc")? SortOrderEnum.ASCENDING:SortOrderEnum.DESCENDING;

((PageSplit) pageList).setSortDirection(sortOrderEnum);

}

if (list != null && ListSize != 0) {

((PageSplit) pageList).setFullListSize(ListSize);

((PageSplit) pageList).setObjectsPerPage(pageSize);

((PageSplit) pageList).setList(list);

} else {

((PageSplit) pageList).setFullListSize(0);

((PageSplit) pageList).setList(null);

}

return pageList;

}

public Object getParam() {

return param;

}

public void setParam(Object param) {

this.param = param;

}

}

四、Service要实现的接口IPageSplitSrv

package util;

import java.util.List;

import java.util.Map;

public interface IPageSplitSrv {

public int findSize(Object obj);

public List search(Map prams,int fromIndex, int toIndex);

public List search(Object obj,Map prams,int fromIndex, int toIndex);

}

五、Service

public class ZVipDataService implements IPageSplitSrv{

private ZVipDataDAO zvipDataDAO;

public int findSize(Object prams) {

return zvipDataDAO.findSize(prams);

}

public List search(Map prams,int fromIndex, int toIndex) {

return zvipDataDAO.search(prams,fromIndex,toIndex);

}

public List search(Object obj,Map prams,int fromIndex, int toIndex) {

return zvipDataDAO.search(obj,prams,fromIndex,toIndex);

}

}

六、DAO

public int findSize(Object prams) {

int size;

Session ses = getHibernateTemplate().getSessionFactory().openSession();

Criteria crt = ses.createCriteria(ZVipData.class);

if(null!=prams){

ZVipData zv = (ZVipData) prams;

crt.add(Example

.create(zv)

.enableLike(MatchMode.ANYWHERE)

.excludeProperty("integral"));

}

crt.setProjection(Projections.rowCount());

size = Integer.parseInt(crt.uniqueResult().toString());

ses.close();

return size;

}

public List search(Map map, int fromIndex, int toIndex) {

Session ses = getHibernateTemplate().getSessionFactory().openSession();

Criteria crt = ses.createCriteria(ZVipData.class);

if(null!=map.get("sdir")&&null!=map.get("sorder")){

Order sortCriterion = map.get("sdir").equals("asc")? Order.asc(map.get("sorder")):Order.desc(map.get("sorder"));

crt .addOrder(sortCriterion);

}

crt .setFirstResult(fromIndex)

.setMaxResults(toIndex);

List list = crt.list();

ses.close();

return list;

}

public List search(Object obj,Map map,int fromIndex, int toIndex) {

ZVipData zv = (ZVipData) obj;

Session ses = getHibernateTemplate().getSessionFactory().openSession();

Criteria crt = ses.createCriteria(ZVipData.class)

.add(Example

.create(zv)

.enableLike(MatchMode.ANYWHERE)

.excludeProperty("integral"));

if(null!=map.get("sdir")&&null!=map.get("sorder")){

Order sortCriterion = map.get("sdir").equals("asc")? Order.asc(map.get("sorder")):Order.desc(map.get("sorder"));

crt .addOrder(sortCriterio澳门新葡亰集团n);

}else{

crt.addOrder(Order.asc("vipcardid"));

}

crt .setFirstResult(fromIndex)

.setMaxResults(toIndex);

List list=crt.list();

ses.close();

return list.size()>0 ? list : null ;

}

七、Control中调用

public ModelAndView searchVip(HttpServletRequest request,

HttpServletResponse response) {

String vipname = request.getParameter("vipname");//会员名

String registerdate = request.getParameter("registerdate");//日期

String vipcardid = request.getParameter("vipcardid"); // 卡号

ZVipData zv = new ZVipData(vipcardid,vipname,registerdate);

GetPageList pageList = new GetPageList(request,zvipDataService);

pageList.setParam(zv);

PaginatedList paginaredList =pageList.getPageList();

request.setAttribute("zvipdatalist", paginaredList);

request.setAttribute("zv", zv);

return new ModelAndView("vip/listVip");

}

您可能还会对下面的文章感兴趣: