实现一个简单的内存分页功能

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u011955252/article/details/89817227
package page;

import java.io.Serializable;
import java.util.List;

public class Response implements Serializable {

    private List  list;

    private boolean hasMore;

    private int nextPageNo;

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public boolean isHasMore() {
        return hasMore;
    }

    public void setHasMore(boolean hasMore) {
        this.hasMore = hasMore;
    }

    public int getNextPageNo() {
        return nextPageNo;
    }

    public void setNextPageNo(int nextPageNo) {
        this.nextPageNo = nextPageNo;
    }

    @Override
    public String toString() {
        return "Response{" +
                "list=" + list +
                ", hasMore=" + hasMore +
                ", nextPageNo=" + nextPageNo +
                '}';
    }
}
package page;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PageTest {

    public static Response memoryPage(List list,int pageSize,int pageNum){
        Response response=new Response();
        if(CollectionUtils.isEmpty(list)) {
            response.setHasMore(false);
            response.setList(Collections.emptyList());
            return response ;
        }
        int from=(pageNum-1)*pageSize;
        int to=pageNum*pageSize;
        int size=list.size();
        response.setHasMore(size>to);
        response.setNextPageNo(pageNum+1);
        if(size>from){
            response.setList(list.subList(from,Math.min(size,to)));
        }
        return response;
    }

    public static void main(String[] args){
        List aa=new ArrayList();
        aa.add(1);
        aa.add(2);
        aa.add(3);
        aa.add(4);
        aa.add(5);
        aa.add(6);
        aa.add(2);

        Response response=memoryPage(aa,2,5);
        System.out.println(response);


    }
}

 

这样就可以一次远程调用获取所有的数据,然后进行内存分页做到分页处理的能力

展开阅读全文

我要实现一个简单功能

03-12

[code=Java] rn static String [] p=new String[10];rn int i0=1;rn int [] add=new int[10];rn int i=1;rn int [] useoffice=new int[10];rn int i1=1;rn int[] usething=new int[10];rn int i2=1;rn int [] spl=new int[10];rn int i3=1;rn int [] sp=new int[10];rn int i4=1;rnrn ResultSet rs0 = stmt.executeQuery("select * from rtype");rn DefaultMutableTreeNode root = new DefaultMutableTreeNode("浏览方式");rn pro = new DefaultMutableTreeNode("资产分类");rn root.add(pro);rnrn while(rs0.next())rn rn this.p[i0]=rs0.getString("t_id");rn String s = rs0.getString("t_type");rn DefaultMutableTreeNode m=new DefaultMutableTreeNode(s);rnrn pro.add(m);rnrn i0++;rnrn rnrnrn ResultSet rs = stmt.executeQuery("select * from addusetype");rn adduse = new DefaultMutableTreeNode("增加方式");rn root.add(adduse);rnrn while (rs.next()) rn String s = rs.getString("a_type");rn DefaultMutableTreeNode a = new DefaultMutableTreeNode(s);rn adduse.add(a);rn add[i] = rs.getInt("a_id");rn i++;rn rnrnrnResultSet rs1=stmt.executeQuery("select * from bumen");rnbumen=new DefaultMutableTreeNode("使用部门");rnroot.add(bumen);rnrn while(rs1.next())rnrn String s1 = rs1.getString("b_value");rn DefaultMutableTreeNode b=new DefaultMutableTreeNode(s1);rn bumen.add(b);rn useoffice[i1]=rs1.getInt("b_id");rn i1++;rnrnrn ResultSet rs2=stmt.executeQuery("select * from isuse");rn isuse=new DefaultMutableTreeNode("使用情况");rn root.add(isuse);rnrn while(rs2.next())rn rn String s2 = rs2.getString("i_value");rn DefaultMutableTreeNode c=new DefaultMutableTreeNode(s2);rn isuse.add(c);rn usething[i2]=rs2.getInt("i_id");rn i2++;rnrnrnrn ResultSet rs3=stmt.executeQuery("select * from saveplace");rn saveplace=new DefaultMutableTreeNode("保存地点");rn root.add(saveplace);rnrn while(rs3.next())rn rn String s3 = rs3.getString("s_value");rn DefaultMutableTreeNode d=new DefaultMutableTreeNode(s3);rn saveplace.add(d);rn spl[i3]=rs3.getInt("s_id");rn i3++;rn rnrn ResultSet rs4=stmt.executeQuery("select * from saveperson");rn savaperson=new DefaultMutableTreeNode("保管人员");rn root.add(savaperson);rnrn while(rs4.next())rn rn String s4 = rs4.getString("sp_value");rn DefaultMutableTreeNode e=new DefaultMutableTreeNode(s4);rn savaperson.add(e);rn sp[i4]=rs4.getInt("sp_id");rn i4++;rn [/code]rnrn把数组的内容和子节点的属性关联 我不知道设置属性的函数 请教啊 rn后点子节点获取相应的ID 就是表的ID 论坛

没有更多推荐了,返回首页