Home  >  Q&A  >  body text

java - 怎么实现调用一个方法后,将该方法中存储的信息,清零啊!!

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

方法代码:

private int currentPageNo3=1;

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

没错这是个分页::

出现的错误情况::
假如第一次调用这个方法时,我点击翻页,在第20页时停止了,当第二次调用这个方法时,在点击翻页,会出现第21页,而不是第二页。

我想实现,每调用完一次这个getFenyePageNo3()方法,就将保存在currentPageNo3里面的值清空,当再次调用这个方法的时候,不会出现currentPageNo3还保存着上一次调用保存的页数。

这样描述还清楚吗

ringa_leeringa_lee2765 days ago674

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 09:46:13

    It depends on how you int pageNo=ps.getFenyePageNo3(param,lastPage);ps this object. If it is a singleton, it will definitely be recorded. If it is new every time, it will definitely not be recorded. Or you assigned currentPageNo3 when passing it in from the front end.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:46:13

    You just need to change the local variables of the currentPageNo3声明为getFenyePageNo3 method

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:46:13

    Is your idea of ​​paging wrong? Wouldn’t it be better to accept two parameters (pageNo, pageSize) directly? Why should we save which page in paging?

    If it is java web, the client and server are not tightly tied to each other like this.

    reply
    0
  • Cancelreply