return pageCount;
}
}
时间有点晚了所以这里就不多解释了。
第七步:在包com.action 建立分页的Action文件名为:softlistAction.java
代码如下:
package com.action;
import com.bean.leavetalk;
import com.bean.soft;
import com.dao.Dao;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
public class softlistAction extends ActionSupport {
private List<soft> softs;//用于数据集合对象并非只是软件
private List<soft> downcountlist;//用于显示下载列表的集合。
private List<leavetalk> leavatalks;//用于显示用户留言列表的集合。
private int pageNow = 1; //初始化为1,默认从第一页开始显示
private int pageSize = 4; //每页显示5条记录
private int pageCount;//总页数
private String doing;//标记Action返回的值
private Dao pageDAO = new Dao();
private Dao leivetalkdao = new Dao();
private int id;
private String fbadcount;
private String fgoodcount;
public List<soft> getSofts() {
return softs;
}
public void setSofts(List<soft> softwares) {
this.softs = softs;
}
public int getPageNow() {
return pageNow;
}
public void setPageNow(int pageNow) {
this.pageNow = pageNow;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageCount() {
Dao sa = new Dao();
sa.getpageCount(pageSize, "");
this.pageCount = sa.getpageCount(pageSize, "");
return sa.getpageCount(pageSize, "");
}
/**
* @param pageCount the pageCount to set
*/
public void setPageCount() {
Dao sa = new Dao();
sa.getpageCount(pageSize, "");
this.pageCount = sa.getpageCount(pageSize, "");
}
/**
* @return the doing
*/
public String getDoing() {
return doing;
}
/**
* @param doing the doing to set
*/
public void setDoing(String doing) {
this.doing = doing;
}
//主方法
public String execute() throws Exception {
String returnstr = "erro";
String HQLstr = "";
// softs = pageDAO.queryByPage(pageSize, pageNow, HQLstr);
if (doing.equals("productlist")) {
returnstr = "productlist";
HQLstr = "from soft sft";
this.setPageSize(4);
this.leavatalks = leivetalkdao.getleavetalks("from leavetalk lt order by lt.id desc");
this.softs = pageDAO.queryByPage(pageSize, pageNow, HQLstr);
} else if (doing.equals("productshow")) {
returnstr = "productshow";
HQLstr = "from soft sft where sft.id='" + getId() + "' order by sft.id asc";
downcountlist = pageDAO.queryByPage(10, pageNow, "from soft sft order by sft.fDownTimes desc");
} else if (doing.equals("index")) {
returnstr = "index";
HQLstr = " from soft sft where sft.ftype='T'order by sft.id asc";
this.setPageSize(5);
} else if (doing.equals("web")) {
returnstr = "web";
HQLstr = " from soft sft where sft.ftype='T'order by sft.id asc";
this.setPageSize(5);
} else if (doing.equals("service")) {
returnstr = "service";
//HQLstr = " from service sr where order by sr.id asc";
// this.setPageSize(1);
} else if (doing.equals("Updatefgood")) {
returnstr = "Updatefgood";
HQLstr = "from soft sft where sft.id='" + getId() + "' order by sft.id asc";
downcountlist = pageDAO.queryByPage(10, pageNow, "from soft sft order by sft.fDownTimes desc");
pageDAO.UpdatefgoodAndfbad(getId(), "updategood", fgoodcount);
} else if (doing.equals("Updatefbad")) {
returnstr = "Updatefgood";
HQLstr = "from soft sft where sft.id='" + getId() + "' order by sft.id asc";
downcountlist = pageDAO.queryByPage(10, pageNow, "from soft sft order by sft.fDownTimes desc");
pageDAO.UpdatefgoodAndfbad(getId(), "updatebad", fbadcount);
} else {
returnstr = "erro";
}
softs = pageDAO.queryByPage(pageSize, pageNow, HQLstr);
System.out.println(softs.size());
return returnstr;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the downcountlist
*/
public List<soft> getDowncountlist() {
return downcountlist;
}
/**
* @param downcountlist the downcountlist to set
*/
public void setDowncountlist(List<soft> downcountlist) {
this.downcountlist = downcountlist;
}
/**
* @return the fbadcount
*/
public String getFbadcount() {
return fbadcount;
}
/**
* @param fbadcount the fbadcount to set
*/
public void setFbadcount(String fbadcount) {
Integer b = Integer.valueOf(fbadcount) + 1;
this.fbadcount = b.toString();
}
/**
* @return the fgoodcount
*/
public String getFgoodcount() {
return fgoodcount;
}
/**
* @param fgoodcount the fgoodcount to set
*/
public void setFgoodcount(String fgoodcount) {
Integer b = Integer.valueOf(fgoodcount) + 1;
this.fgoodcount = b.toString();
}
/**
* @return the leavatalks
*/
public List<leavetalk> getLeavatalks() {
return leavatalks;
}
/**
* @param leavatalks the leavatalks to set
*/
public void setLeavatalks(List<leavetalk> leavatalks) {
this.leavatalks = leavatalks;
}
}