简体   繁体   中英

How to paginate in spring ldap using skip value

Can any body help me on how I can find some record from LDAP using springldap.

My problem is, I have created a rest service and it accepts some parameter. One is offset and another is limit. Offset parameter escape some record like if my ldap server have 500 record. Now if I give offset value 1 and LIMIT is 100. then it should give first 100 record from ldap. If I give offset value 100 and LIMIT is 100, then it should give 100 record after first 100 record from ldap. If I give offset value 50 and LIMIT is 10, then it should give 10 record after first 50 record from ldap.

I am stuck on how to set offset value in spring ldap template. I have set limit value and it is working fine.

I am sharing peace of code.

public OrganisationGroups getOrganisationGroup() 
{

    SearchControls controls = new SearchControls();

    controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    controls.setCountLimit(MAXIMUM_SEARCH_GROUP_COUNT);
    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("objectclass", "groupOfUniqueNames"));
    List<OrganisationGroup> organisationGroup = ldapTemplate.search("", filter.toString(), controls, new GroupSearchMapper());

    OrganisationGroups groups = new OrganisationGroups();
    groups.setOrganisationGroup(organisationGroup);
    groups.setCount(organisationGroup.size());
    return groups;
}

In this code I have set MAXIMUM_SEARCH_GROUP_COUNT variable to find out maximum record from ldap. But I am not able to set parameter or any other way to escape some records from beginning.

Your best option is to use the Virtual List View request control (link to specification ) also known as VLV. Note that to use VLV, you will need to make configuration changes on your LDAP server (I assume you are using OpenDJ, which supports VLV ).

There is a code example for JNDI LDAP provider with the VLV request control at this forum .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM