Home  >  Q&A  >  body text

java - 怎么清除一个方法里面缓存的数据?

调用此方法:
int pageNo=ps.getFenyePageNo(param,lastPage);

具体方法:
private int currentPageNo=1;

public int getFenyePageNo(String param, int lastPage) {
    if ("first".equals(param) || null == param) {
        currentPageNo = 1;
    }
    else if ("next".equals(param)) {
        if (currentPageNo < lastPage) {
            System.out.println("当前页3::"+currentPageNo);
            currentPageNo++;    
        }
    } 
    else if ("previous".equals(param)) {
        if (currentPageNo > 1) {
            currentPageNo--;
        }
    }
    else if ("last".equals(param)) {
        currentPageNo = lastPage;
    }
    return currentPageNo;
}

现在的问题就是::调用一次方法,数据就保存在currentPageNo里面了,需要不停的调用这个方法。
有没有什么办法,能每次调用完这个方法之后,就能清除这个方法里面的数据!!!

清除数据是我想要的结果,,哪位大神有什么好办法吗?????

PHPzPHPz2765 days ago595

reply all(5)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:47:41

    The definition is wrong, the front end only passes 第几页每页size就行了,然后后端算出limit,offset, finds the data, and returns it to the front end.

    The request and return are as follows:

    前端请求(仅分页相关数据):
        private int pageNo = 1;
        /** 每页条数 */
        private int pageSize = 10;
    后端返回(仅分页相关数据):
        /** 第几页 */
        private int pageNo = 1;
        /** 每页条数 */
        private int pageSize = 10;
        /** 总页数 */
        private int pageCount;
        /** 总记录数 */
        private int recordCount;

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:47:41

    Defined as local variable return

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:47:41

    For issues like pagination, it is best to have a common base class in the project. The public classes standardize the common features of paging. Because all list page queries need to use paging. The recommended code is as follows:

    import java.util.Date;
    //类QueryBaseDo.java的实现描述:分页查询对象的基类
    public class QueryBaseDo {
        /** 查询结果总记录数 */
        private Integer         totalCount;
        // 默认一页10条数据
        public static final int DEFAULT_PAGE_SIZE = 10;
        // 默认从第一页开始
        public static final int DEFAULT_PAGE_NO   = 1;
        // 页面大小
        private int             pageSize          = DEFAULT_PAGE_SIZE;
        // 第几页
        private int             pageNum           = DEFAULT_PAGE_NO;
        // 这个值一般由服务端设置
        private int             total             = Integer.MAX_VALUE;
        // 是否要获取总页数,如果用户点分页查询第2页到第N页可以不用查询记录总数
        private boolean         needPageTotal     = true;
    
        /**
         * 是否进行分页
         */
        private boolean         doPage            = true;
    
        private String          creator;
    
        private Date            gmtCreate;
    
        private String          modifier;
    
        private Date            gmtModified;
    
        private String          isDeleted         = "n";
    
        private Integer         skip              = 0;
        private Integer         take              = 10;
    
        public Integer getSkip() {
            return skip;
        }
    
        public void setSkip(Integer skip) {
            this.skip = skip;
        }
    
        public Integer getTake() {
            return take;
        }
    
        public void setTake(Integer take) {
            this.take = take;
        }
    
        public Integer getTotalCount() {
            return totalCount;
        }
    
        public void setTotalCount(Integer totalCount) {
            this.totalCount = totalCount;
        }
    
        public int getPageSize() {
            if (pageSize <= 0) {
                pageSize = DEFAULT_PAGE_SIZE;
            }
            return pageSize;
        }
    
        public void setPageSize(int pageSize) {
            if (pageSize < 0) {
                pageSize = DEFAULT_PAGE_SIZE;
            }
            this.pageSize = pageSize;
        }
    
        public int getPageNum() {
            // total已经被赋值,修正pagenum 的值
            if (Integer.MAX_VALUE != total && total > 0) {
                pageNum = Math.min(pageNum, (int) Math.ceil((double) total / pageSize));
            }
    
            if (pageNum <= 0) {
                pageNum = DEFAULT_PAGE_NO;
            }
            return pageNum;
        }
    
        public void setPageNum(int pageNum) {
            if (pageNum <= 0) {
                pageNum = DEFAULT_PAGE_NO;
            }
            this.pageNum = pageNum;
        }
    
        public int getStartNum() {
            int startNum = getPageSize() * (getPageNum() - 1);
            if (startNum < 0) {
                startNum = 0;
            }
            return startNum;
        }
    
        public int getTotal() {
            return total;
        }
    
        public void setTotal(int total) {
            this.total = total;
        }
    
        public boolean isNeedPageTotal() {
            return needPageTotal;
        }
    
        public void setNeedPageTotal(boolean needPageTotal) {
            this.needPageTotal = needPageTotal;
        }
    
        public boolean isDoPage() {
            return doPage;
        }
    
        public void setDoPage(boolean doPage) {
            this.doPage = doPage;
        }
    
        public String getCreator() {
            return creator;
        }
    
        public void setCreator(String creator) {
            this.creator = creator;
        }
    
        public Date getGmtCreate() {
            return gmtCreate;
        }
    
        public void setGmtCreate(Date gmtCreate) {
            this.gmtCreate = gmtCreate;
        }
    
        public String getModifier() {
            return modifier;
        }
    
        public void setModifier(String modifier) {
            this.modifier = modifier;
        }
    
        public Date getGmtModified() {
            return gmtModified;
        }
    
        public void setGmtModified(Date gmtModified) {
            this.gmtModified = gmtModified;
        }
    
        public String getIsDeleted() {
            return isDeleted;
        }
    
        public void setIsDeleted(String isDeleted) {
            this.isDeleted = isDeleted;
        }
    
        public static int getDefaultPageSize() {
            return DEFAULT_PAGE_SIZE;
        }
    
        public static int getDefaultPageNo() {
            return DEFAULT_PAGE_NO;
        }
    
    }
    

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:47:41

    The page has a hidden field, which is used to store the current page No. When jumping to the page, currentPage No is submitted to the server and assigned a value.
    It doesn’t matter whether the currentPageNo on the server is local or not, it is reassigned every time. If no value is submitted, it will be assigned a value of 1

    Your actions all inherit a baseAction. This baseAction implements the Ipage interface, which implements the page, including the total number of pages, the page number, and the size of each page. . .

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:47:41

    Local variables are done

    reply
    0
  • Cancelreply