java - 怎么实现调用一个方法后,将该方法中存储的信息,清零啊!!
ringa_lee
ringa_lee 2017-04-18 09:44:13
0
3
667

调用方法:
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_lee
ringa_lee

ringa_lee

reply all(3)
洪涛

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.

黄舟

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

洪涛

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!