问题描述
我使用两种方式修改用户属性当传入的属性为空字符串时就抱错请高手看看这是什么原因不然设置不了空值javax.naming.directory.InvalidAttributeValueException:[LDAP:errorcode21-00000057:LdapErr:DSID-0C090A85,comment:Errorinattributeconversionoperation,data0,vece]remainingname'CN=,OU=,OU=,OU=,DC=,DC='2011-7-1310:50:51dao.impl.UserDaoImpleditUsers严重:null方式1Attributesattrs=newBasicAttributes();if(user.getTelephone()!=null&&!"".equals(user.getTelephone())){attrs.put(newBasicAttribute("telephoneNumber",user.getTelephone()));}if(user.getMobile()!=null&&!"".equals(user.getMobile())){attrs.put(newBasicAttribute("mobile",user.getMobile()));}if(user.getFax()!=null&&!"".equals(user.getFax())){attrs.put(newBasicAttribute("facsimileTelephoneNumber",user.getFax()));}if(user.getPosition()!=null&&!"".equals(user.getPosition())){attrs.put(newBasicAttribute("title",user.getPosition()));}if(user.getAddress()!=null&&!"".equals(user.getAddress())){attrs.put(newBasicAttribute("physicalDeliveryOfficeName",user.getAddress()));}ldcx.modifyAttributes(user.getDisName(),DirContext.REPLACE_ATTRIBUTE,attrs);returntrue;方式2ModificationItem[]mods=newModificationItem[5];//DirContext.REPLACE_ATTRIBUTE修改属性//newBasicAttribute("telephoneNumber",user.getTelephone())修改//把user的属性不为空的加入修改//否则报错javax.naming.directory.InvalidAttributeValueException:mods[i]=newModificationItem(DirContext.REPLACE_ATTRIBUTE,newBasicAttribute("telephoneNumber",user.getTelephone()));mods[i]=newModificationItem(DirContext.REPLACE_ATTRIBUTE,newBasicAttribute("mobile",user.getMobile()));mods[i]=newModificationItem(DirContext.REPLACE_ATTRIBUTE,newBasicAttribute("facsimileTelephoneNumber",user.getFax()));mods[i]=newModificationItem(DirContext.REPLACE_ATTRIBUTE,newBasicAttribute("title",user.getPosition()));mods[i]=newModificationItem(DirContext.REPLACE_ATTRIBUTE,newBasicAttribute("physicalDeliveryOfficeName",user.getAddress()));//执行修改//ldcx.modifyAttributes(user.getDisName(),DirContext.REPLACE_ATTRIBUTE,mods);