gpt4 book ai didi

java - 使用 Spring Boot 从 LDAP 排序记录

转载 作者:行者123 更新时间:2023-11-30 12:08:14 24 4
gpt4 key购买 nike

如何正确地从 LDAP 目录中获取排序的记录。由于数据量大,全部加载到内存然后排序非常耗时。这就是为什么我想要(使用 Spring Boot/SpringLDAP)从 LDAP 获取已经排序的记录。

我尝试在@Repository 中创建

@Repository
public interface XxxRepository extends LdapRepository<Xxx>, Serializable {

List<Xxx> findAllByOrderByNameAsc(LdapQuery ldapQuery);

}

它不起作用,NullPointerException。

我的@Entity 看起来像:

@Entry(base = "", objectClasses = {"xxx", "xxx"})
public class Xxx implements Serializable {
@Id
private Name dn;

@Attribute(name = "name")
@DnAttribute(value = "name", index = 0)
private String name;

.
.
.
}

我的@Service

public void search() {
String filterConditions = "(&(objectClass=Xxx)";
filterConditions += "(name=*)";
LdapQuery query = query().base(BASE_UNIT).filter(filterConditions + ")");
List<Xxx> xxx= xxxRepository.findAllByOrderByNameAsc(query);
}

最佳答案

我在这里找到了答案:Spring-LDAP LdapTemplateSortedSearchITest

public void testSearch_SortControl_ConvenienceMethod() {
SortControlDirContextProcessor requestControl;

// Prepare for first search
requestControl = new SortControlDirContextProcessor("cn");
tested.search(BASE, FILTER_STRING, searchControls, callbackHandler,
requestControl);
int resultCode = requestControl.getResultCode();
boolean sorted = requestControl.isSorted();
assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue();
List list = callbackHandler.getList();
assertSortedList(list);
}

它使用SortControlDirContextProcessor

关于java - 使用 Spring Boot 从 LDAP 排序记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54418685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com