Spring LDAP SDK 实现 LDAP 查询计数:替代命令行操作
这是一个命令行命令,可以在终端或者命令行中执行。如果您想使用 Spring LDAP SDK 来执行这个命令,可以编写如下 Java 代码:
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.filter.*;
import org.springframework.ldap.query.LdapQueryBuilder;
// 构建查询条件
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectClass", "*"));
filter.and(new LikeFilter("cn", "crl*"));
// 构建LDAP模板
LdapTemplate ldapTemplate = new LdapTemplate(/* 这里填写您的LDAP配置 */);
// 执行查询
int count = ldapTemplate.count(LdapQueryBuilder.query().base("c=cn").filter(filter));
System.out.println(count);
这个代码会执行与命令行命令相同的查询,并输出满足条件的条目数量。您需要根据实际情况填写 LDAP 配置。
原文地址: https://www.cveoy.top/t/topic/nGEd 著作权归作者所有。请勿转载和采集!