接上一篇
7 FavoriteService接口
package cn.itcast.travel.service;
import cn.itcast.travel.domain.PageBean;
import cn.itcast.travel.domain.Route;
import java.util.List;
public interface FavoriteService {
PageBean findRouteOrderPageBean(String cid, String currentPage, String cname, String highPrice, String lowPrice, String pageSize);
}
8 实现类FavoriteServiceImp
package cn.itcast.travel.service.impl;
import cn.itcast.travel.dao.FavoriteDao;
import cn.itcast.travel.dao.RouteDao;
import cn.itcast.travel.dao.impl.FavoriteDaoImp;
import cn.itcast.travel.dao.impl.RouteDaoImp;
import cn.itcast.travel.domain.Favorite;
import cn.itcast.travel.domain.PageBean;
import cn.itcast.travel.domain.Rid;
import cn.itcast.travel.domain.Route;
import cn.itcast.travel.service.FavoriteService;
import java.util.ArrayList;
import java.util.List;
public class FavoriteServiceImp implements FavoriteService {
FavoriteDao favoriteDao= new FavoriteDaoImp();
RouteDao routeDao=new RouteDaoImp();
@Override
public PageBean findRouteOrderPageBean(String cid, String currentPage, String cname, String highPrice, String lowPrice, String pageSize) {
int icid=0;
if(cid!=""&&cid!=null&&cid!="null"){
int i = Integer.parseInt(cid);
}
int icurrentPage=1;
if(currentPage!=""&¤tPage!=null&¤tPage!="null"){
icurrentPage = Integer.parseInt(currentPage);
}
int ihighPrice=-1;
if(highPrice!=""&&highPrice!=null&&highPrice!="null"){
ihighPrice = Integer.parseInt(highPrice);
}
int ilowPrice=-1;
if(lowPrice!=""&&lowPrice!=null&&lowPrice!="null"){
ilowPrice = Integer.parseInt(lowPrice);
}
int ipageSize=0;
if(pageSize!=""&&pageSize!=null&&pageSize!="null"){
ipageSize = Integer.parseInt(pageSize);
}
/*
* order排序书说明:
* 0为不排序
* 1为根据单个路线总收藏排序
* 2 根据最新事件排序
* 3 根据是否主题排序
* */
int order=1;
PageBean<Route> pageBean=new PageBean<>();
pageBean.setCurrentPage(icurrentPage);
pageBean.setPageSize(ipageSize);
int startPage=(icurrentPage-1)*ipageSize;
List<Route> list=routeDao.findRouteByPage(icid,startPage,ipageSize,cname,ihighPrice,ilowPrice,order);
for (Route route : list) {
System.out.println(route.getCount());
}
pageBean.setList(list);
int totalCount = routeDao.findTotalCount(icid,cname,ihighPrice,ilowPrice,order);
pageBean.setTotalCount(totalCount);
int totalPage=totalCount%ipageSize==0?totalCount/ipageSize:((totalCount/ipageSize)+1);
pageBean.setTotalPage(totalPage);
return pageBean;
}
}