本文介绍了从NamingEnumeration中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在LDAP服务器上搜索人员.

My application searches an LDAP server for people.

return ldapTemplate.search("", "(objectclass=person)", new AttributesMapper() {
      public Object mapFromAttributes(Attributes attrs)
                                                     throws NamingException {

        return attrs.get("cn").getAll();
      }
    });

它返回NamingEnumeration对象的列表,其中包含矢量.每个向量可以包含一个或多个值.我可以通过此代码打印人名

It returns list of NamingEnumeration object, which contains vectors in it. Each vector may contain one or more values.I can print person names by this code

for(NamingEnumeration ne : list){
  while (ne.hasMore()) {
      System.out.println("name is : " + ne.next().toString());
    }
  }

因为我的ldap搜索可以包含多个值,所以它出现在NamingEnumeration对象内的vector中.如何从中获取多个值.

As my ldap search can contain mutiple values so that comes in vector inside NamingEnumeration object. How can I get multiple values out of it.

推荐答案

由于您正在使用javax.naming.NamingEnumeration<java.util.Vector>java.util.List,例如

As you are using a java.util.List of javax.naming.NamingEnumeration<java.util.Vector> such as this,

List<NamingEnumeration<Vector>> list

您应该能够遍历每个NamingEnumeration中的Vector:

You should be able to iterate over the Vector in each NamingEnumeration:

for (NamingEnumeration<Vector> ne : list) {
    while (ne.hasMore()) {
        Vector vector = ne.next();
        for (Object object : vector) {
            System.out.println(object);
        }
    }
}

请注意, Vector 是尽管并未弃用,但许多人认为它们已经过时了.同样,封闭的集合可以使用类型参数.如果您有选择,请考虑以下替代方法之一:

Note that Vector is considered by many to be obsolescent, although not deprecated. Also, the enclosed collection could use a type parameter. If you have a choice, consider one of these alternatives:

List<NamingEnumeration<Vector<T>>>
List<NamingEnumeration<List<T>>>

这篇关于从NamingEnumeration中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 16:02