package com.tarena.action;
import java.util.ArrayList;
import java.util.HashMap;import java.util.List;import java.util.Map;import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import com.tarena.dao.CostDao;
import com.tarena.entity.Condition;import com.tarena.entity.Cost;import com.tarena.entity.Page;@Controller
public class CostAction { @Resource private CostDao costDao; List<Cost> list; // 结果集 private Page page;// 分页查找的实体类 private int pages;// 网页传回的要跳转的页面 private int countpage = 4;// 传给页面的页码数 private int totalPage;// 总页数 private Cost cost;private String name;// 资费名
private Map<String, Object> info = new HashMap<String, Object>();// 提示信息 public String getName() { return name; }public void setName(String name) {
this.name = name; }public Map<String, Object> getInfo() {
return info; }public void setInfo(Map<String, Object> info) {
this.info = info; }public Cost getCost() {
return cost; }public void setCost(Cost cost) {
this.cost = cost; }public int getTotalPage() {
return totalPage; }public void setTotalPage(int totalPage) {
this.totalPage = totalPage; }public int getCountpage() {
return countpage; }public void setCountpage(int countpage) {
this.countpage = countpage; }public Page getPage() {
return page; }public void setPage(Page page) {
this.page = page; }public int getPages() {
return pages; }public void setPages(int pages) {
this.pages = pages; }public List<Cost> getList() {
return list; }public void setList(List<Cost> list) {
this.list = list; }/**
* 根据页面返回的页码查询对应的cost列表 * * @return */ public String findCost() { list = costDao.findAll(); totalPage = list.size() / page.getPageCount() + 1;Condition cond = new Condition();
List<Integer> ids = new ArrayList<Integer>();if (pages != 0) {
page.setPages(pages); if (pages > 4 ){ countpage = pages ; } if(pages==totalPage){ countpage = pages-1; }for (int i = 0; i < page.getPageCount(); i++) {
ids.add((page.getPages() - 1) * page.getPageCount() + i + 1); } cond.setIds(ids); list = costDao.findByIds(cond); } else { page.setPages(1); pages = 1; countpage = pages + 3; for (int i = 0; i < page.getPageCount(); i++) { ids.add((page.getPages() - 1) * page.getPageCount() + i + 1);}
cond.setIds(ids); list = costDao.findByIds(cond); }return "find";
}