1. 下载spring-ldap-1.3.0.RELEASE-with-dependencies.zip,里面doc,demo很全面,jar基本满足要求。
2. 附带的junit的test还是别运行了,跑好累了都不动。
3. demo中附带了\samples\demos\demo-tiger\src\test\resources\config\setup_data.ldif,可直接放入BDB。但放入前需先建立根节点,例如可使用下列代码建立:
dn: dc=jayway,dc=seobjectclass: dcObjectobjectclass: organizationo: Example Companydc: jaywaydn: cn=root,dc=jayway,dc=seobjectclass: organizationalRolecn: root
4. 对象中存在外键的概念,假如有一复合对象,若想为对象属性赋值,不必须先建立此属性的对象。
dn: c=Sweden,dc=jayway,dc=seobjectclass: topobjectclass: countryc: Swedendescription: The country of Swedendn: ou=company1,c=Sweden,dc=jayway,dc=seobjectclass: topobjectclass: organizationalUnitou: company1description: First company in Sweden
ou=company1,c=Sweden,dc=jayway,dc=se对象建立前,c=Sweden必须先建立好。在java中对象亦如此。
package org.springframework.ldap.demo.dao;import java.util.List;import org.springframework.ldap.demo.domain.Person;public class Test { PersonDaoImpl dao = new PersonDaoImpl(); public Test() { super(); init(); } public final void init() { dao.setBase("dc=jayway,dc=se"); dao.setPassword("secret"); dao.setUrl("ldap://localhost/"); dao.setUserDn("cn=root,dc=jayway,dc=se"); } public static void main(String[] args) { Test test = new Test(); Listnames = test.dao.getAllPersonNames(); for (String name : names) { System.out.println(name); } Person person = test.dao.findByPrimaryKey("Sweden", "company1", "Sam Tsui"); person.setDescription("我靠"); test.dao.update(person); System.out.println(person); } public void addPerson() { Person person = new Person(); person.setCompany("company1"); person.setCountry("Sweden"); person.setDescription("Power Charge."); person.setFullName("Sam Tsui"); person.setLastName("Tsui"); person.setPhone("12345"); dao.create(person); } public void deletePerson() { Person person = new Person(); person.setCompany("company1"); person.setCountry("Sweden"); person.setFullName("Sam Tsui"); dao.delete(person); }}