AttributesMapper(二):返回Person对象

返回Person对象的AttributesMapper

Person对象与Attributes转换类:
 
private class PersonAttributesMapper implements AttributesMapper<Person> {
      public Person mapFromAttributes(Attributes attrs) throws NamingException {
         Person person = new Person();
         person.setFullName((String)attrs.get("cn").get());
         person.setLastName((String)attrs.get("sn").get());
         person.setDescription((String)attrs.get("description").get());
         return person;
      }
   }

使用方式:
 
ldapTemplate.search(query().where("objectclass").is("person"), new PersonAttributesMapper());
posted @ 2018-05-02 20:44  CryDongle  阅读(15)  评论(0编辑  收藏  举报