我知道有一个简单的答案,但我似乎无法在任何地方找到它。
下面是一小段代码。有人可以告诉我如何列出 rsa 对象的所有属性及其关联值吗?
提前致谢,
NamingEnumeration answer = executeSearch(context,env,sBaseDN);
while (answer.hasMore()) { // For each ou
SearchResult sr = (SearchResult) answer.next();
Attributes rsa = sr.getAttributes();
// How do I list all the attributes that were returned?
最佳答案
您可以通过调用 Attributes 的 getAll()
方法来获取 NamingEnumerations 的集合,然后迭代该集合以获取属性值,例如:
try {
for (NamingEnumeration attr = rsa.getAll(); attr.hasMore();) {
Attribute attribute= (Attribute) attr.next();
System.out.println("Attribute id: " + attribute.getID());
for (NamingEnumeration val = attribute.getAll(); val.hasMore();){
System.out.println("Attribute value: " + val.next());
}
}
} catch (NamingException e) {
e.printStackTrace();
}
关于java - 如何列出 Java 属性对象中的所有值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32950246/