81,092
社区成员
发帖
与我相关
我的任务
分享
public ActionForward doView2(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm dyForm = (DynaActionForm) form;
com.ebuilds.util.common.LoginInfo logininfo = (com.ebuilds.util.common.LoginInfo) request.getSession().getAttribute("LoginInfo");
String username = logininfo.getName();
String uid = null;
List list = new ArrayList();
try {
DB db = new DB();
ResultSet rs = db.qu("select * from userinfo where username = '" +
username+"'");
while(rs.next()){
uid = rs.getString("id");
}
if(uid != null){
ResultSet rs1 = db.qu("select * from userinfo where pid = '" +
uid+"'");
while(rs1.next()){
Map map = new HashMap();
map.put("id", rs1.getString("id"));
map.put("pid", rs1.getString("pid"));
map.put("username", rs1.getString("username"));
map.put("name", rs1.getString("name"));
list.add(map);
}
}
db.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
dyForm.set("dtos", list);
return mapping.findForward("doView2");
}
public class PageUtil {
public static final int SIZE20 = 20;
private int pageSize;//页面显示条数
private int recordCount;//记录总数
private int currentPage; //当前页
private int fromIndex;
private int toIndex;
private int pageCount;
private int currentPageSize;
public PageUtil(){
this(0,0,1);
}
public PageUtil(int pageSize, int recordCount, int currentPage) {
this.pageSize = pageSize;
this.recordCount = recordCount;
setCurrentPage(currentPage);
}
public PageUtil(int pageSize, int recordCount) {
this(pageSize, recordCount, 1);
}
public int getNextPage(){
return currentPage + 1 > getPageCount() ? getPageCount() : currentPage + 1;
}
public int getPrevPage(){
return currentPage - 1 < 1 ? 1 : currentPage - 1;
}
public int getCurrentPageSize() {
return getToIndex() - getFromIndex();
}
//总页数
public int getPageCount() {
if(pageSize==0)
return 1;
int size = recordCount/pageSize;
int mod = recordCount % pageSize;
if(mod != 0)
size++;
return recordCount == 0 ? 1 : size;
}
//包含,起始索引为0
public int getFromIndex() {
System.out.println("from index:"+(currentPage-1) * pageSize);
return (currentPage-1) * pageSize;
}
//不包含
public int getToIndex() {
System.out.println("to index:"+Math.min(recordCount, currentPage * pageSize));
return Math.min(recordCount, currentPage * pageSize);
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
int validPage = currentPage <= 0 ? 1 : currentPage;
validPage = validPage > getPageCount() ? getPageCount() : validPage;
this.currentPage = validPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getRecordCount() {
return recordCount;
}
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}
}