• Spring Ldap 分页


    LDAP.search()当查询的数据较多时,当查询的数目较大时,会导致内存溢出,因此采用Ldap的分页进行查询

    [java] view plaincopy在CODE上查看代码片派生到我的代码片
    1. public class ChraUserService  
    2. {  
    3. @Autowired  
    4. SearchEmployeeLdapDao searchEmployeeLdapDao;  
    5. public void employeeinfo()  
    6. {  
    7.  PagedResultsCookie cookie=null;  
    8.  PagedResult list=null;   
    9.  SearchEmployeeLdapDao.Initldap();//初始化Ldap  
    10.  do {   
    11.    list=searchEmployeeLdapDao.searchlist(cookie); //获得查询分页的List  
    12.    cookie=list.getCookie();  
    13.    } while (list.getCookie().getCookie()!=null);//判断是否结束  
    14.  }  
    15. }  
    [java] view plaincopy在CODE上查看代码片派生到我的代码片
    1. public class SearchEmployeeLdapDao  
    2. {  
    3. @Autowired  
    4. LdapTemplate ldapTemplate;//spring LDap dataSource  
    5. private AndFilter filter = null;  
    6. private SearchControls searchControls=null;  
    7. public void initldap()  
    8. {  
    9. ldapTemplate.setIgnorePartialResultException(true);  
    10. filter=new AndFilter(); //查询的过滤条件  
    11. filter.and(new EqualsFilter("objectclass""user"));  
    12. filter.and(new LikeFilter("uid""Tim*"));  
    13. searchControls = new SearchControls();  
    14. searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );  
    15. String[] s={"employeeNumber","uid","department","mail","title","thumbnailPhoto"}; //查询返回的字段  
    16. searchControls.setReturningAttributes(s);  
    17. }  
    18. public PagedResult searchlist(PagedResultsCookie cookie)  
    19. {  
    20. PagedResultsRequestControl control = new PagedResultsRequestControl(pagesize, cookie);  
    21. List<MemberBean> list= ldapTemplate.search( "", filter.encode(),searchControls, new ChraUserAttributesMapper(),control);  
    22. return new PagedResult(list, control.getCookie());  
    23. }  
    [java] view plaincopy在CODE上查看代码片派生到我的代码片
    1. public class ChraUserAttributesMapper implements AttributesMapper  
    2. {  
    3. @Override  
    4. public MemberBean mapFromAttributes(Attributes attrs) throws NamingException {  
    5. NamingEnumeration<? extends Attribute> en = attrs.getAll();  
    6. while (en.hasMoreElements())  
    7. {  
    8. BasicAttribute object = (BasicAttribute) en.nextElement();  
    9. //业务逻辑  
    10. }  
    11. }  

    spring LDAP的xml配置文件

    [html] view plaincopy在CODE上查看代码片派生到我的代码片
    1. <beans>  
    2. <bean id="contextSource"  
    3. class="org.springframework.ldap.core.support.LdapContextSource">  
    4. <property name="url" value="***********************" />  
    5. <property name="base" value="*********************" />  
    6. <property name="referral" value="follow"/>  
    7. </bean>  
    8. <bean id="ldapTemplate"  
    9. class="org.springframework.ldap.core.LdapTemplate">  
    10. <constructor-arg ref="contextSource" />  
    11. </bean>  
  • 相关阅读:
    setup slack检查
    关于derive_pll_clock
    STA中的postmap和postfit
    sdc中对I/O口的约束set_input/output_delay
    hold slack的计算
    DDR I 和DDR II的简单比较
    ORA00600: 内部错误代码,参数: [kcratr1_lostwrt], [], [], [], [], [], [], []
    linux解压超过2G大文件
    linux 安装apache2.2.4
    plsql developer导出csv乱码问题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13318068.html
Copyright © 2020-2023  润新知