⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paginationservice.java

📁 基于struct结构的jsp
💻 JAVA
字号:
package com.ntsky.util;

import javax.servlet.http.*;
import com.ntsky.xml.bbs.TopicConfigXML;
import org.apache.log4j.Logger ;
/**
 * <p>Title: Ntsky OpenSource BBS</p>
 * <p>Description: 分页实现类</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: WWW.FM880.COM</p>
 * @author 姚君林
 * @version 1.0
 */

public class PaginationService implements Pagination{
    private final static Logger logger = Logger.getLogger(PaginationService.class);
    private static PaginationService paginationService = null;
    private static Object object = new Object();

    private int page ;
    private int totalPage;//总页数

    private PaginationService(){}

    public static PaginationService getInstance() {
        if (paginationService == null) {
            //使用synchronzed保证一次只有一个实例能访问DBUser对象
            synchronized (object) {
                if (paginationService == null) {
                    try {
                        paginationService = new PaginationService();
                    }
                    catch (Exception e) {
                        logger.error(
                            "PaginationService Exception  " +
                            e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
        }
        return paginationService;
    }

    /**
     * 页面page值
     */
    public int getPage(HttpServletRequest request, String strPage){
        try {
            String tempPage = request.getParameter(strPage);
            if(tempPage == null){
                page = 1;
            }
            else{
                page = Integer.parseInt(tempPage);
            }
        }
        catch (Exception e) {
            logger.error("获取页面数错误 :" + e.getMessage());
        }
        return page;
    }

    /**
     * 主题设置总页数
     */
    public int getTotalPage(int totalRecord){
       int temp;
       int maxNum = TopicConfigXML.getInstance().getTopicConfigXML().getTopicNum();
       temp = totalRecord % maxNum;
       if(temp == 0)
           totalPage = totalRecord/maxNum;
       else
           totalPage = totalRecord/maxNum + 1;
       logger.info("totalPage = " + totalPage);
       return totalPage;
   }

   /**
    * 用户总数
    */
   public int getTotalPage(int totalRecord,int maxNum) {
       int temp = totalRecord % maxNum;
       if (temp == 0)
           totalPage = totalRecord / maxNum;
       else
           totalPage = totalRecord / maxNum + 1;
       logger.info("totalPage = " + totalPage);
       return totalPage;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -