您可以在运行时有效地使用过滤器来指定要用于搜索的内容以及不依赖于某些规则或您对属性的NULL验证。 PLS发现其获取在ldapTemplate使用过滤器人名示例代码: -
public static final String BASE_DN = "dc=xxx,dc=yyy";
private LdapTemplate ldapTemplate ;
public List getPersonNames() {
String cn = "phil more";
String sn = "more";
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person"));
filter.and(new EqualsFilter("sn", sn));
filter.and(new WhitespaceWildcardsFilter("cn", cn));
return ldapTemplate.search(
BASE_DN,
filter.encode(),
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get("cn").get();
}
});
}
正如名字所暗示的AndFilters加入像EqualFilter查找该检查属性的平等而WhitespaceWildcardsFilter执行通配符搜索中使用的所有单独的过滤器。因此,就像我们得到cn = phil更多,它反过来使用*phil*more*
进行搜索。
谢谢Avis ... AND过滤器正是我需要的 – NimmyKrish