java报空指针异常
public String updateMem(Member member){
try {
//根据id获取实体
Member persistent = memberdao.get(member.getId());
//email不为空
if(StringUtils.isNotEmpty(member.getEmail())){
if(this.isEmail(persistent.getEmail())){
persistent.setEmail(member.getEmail());
}else{
code="403";
}
}
//电话不为空
if(StringUtils.isNotEmpty(member.getMobile())){
if(this.isMobile(persistent.getMobile())){
persistent.setMobile(member.getMobile());
}else{
code="402";
}
}
//密码不为空时
if (StringUtils.isNotEmpty(member.getPassword())) {
String oldPassword = DigestUtils.md5Hex(member.getOldPassword());
if(oldPassword.equals(persistent.getPassword())){
String passwordMd5 = DigestUtils.md5Hex(member.getPassword());
persistent.setPassword(passwordMd5);
}else{
code = "408";
}
}
**//BeanUtils.copyProperties(member, persistent, new String[] {"id", "username", "isAccountEnabled", "isAccountLocked", "loginFailureCount", "lockedDate", "registerIp", "loginIp", "loginDate", "passwordRecoverKey"});**
memberdao.update(persistent);
memberdao.flush();
code="200";
} catch (Exception e) {
code="300";
e.printStackTrace();
}
return code;
}
我加这一句的时候就报空指针导常:
**//BeanUtils.copyProperties(member, persistent, new String[] {"id", "username", "isAccountEnabled", "isAccountLocked", "loginFailureCount", "lockedDate", "registerIp", "loginIp", "loginDate", "passwordRecoverKey"});**
测试操作test()方法
//更新开始
System.out.println("请输入原始密码:");
String oldPassword = scan.next();
System.out.println("请输入新密码:");
String newPassword = scan.next();
// System.out.println("请输入邮箱:");
// String email = scan.next();
// member.setEmail(email);
member.setOldPassword(oldPassword);
member.setId("4028eee4399010c601399010e1f60000");
member.setPassword(newPassword);
System.out.println(memberService.updateMem(member));
求解。。
错误信息
花祭梨果凛
12 years, 3 months ago