瞎子传奇之寻找眼珠子

74 阅读1分钟

今日份报错

错误信息

2023-08-16 19:14:20.956 ERROR 9524 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:

报错提示

### Error updating database.  Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'name' cannot be null
### The error may exist in file [D:\java\project\take-out\sky-take-out-75\sky-server\target\classes\mapper\EmployeeMapper.xml]
### The error may involve com.sky.mapper.EmployeeMapper.save-Inline
### The error occurred while setting parameters
### SQL: insert into employee             (name,username,password,phone,sex,id_number,status,create_time,update_time,create_user,update_user)         values             (?,?,?,?,?,?,?,?,?,?,?)
### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'name' cannot be null
; Column 'name' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'name' cannot be null] with root cause

报错原因

//2、处理业务
// 2.1 判断当前用户名是否已经被注册了
Employee employee = employeeMapper.getByUsername(username);
//如果重复,直接返回:用户名己存在
if (!Objects.isNull(employee)){
    throw new AccountExistsException(MessageConstant.ACCOUNT_FOUND);
}
//2.2 补全实体属性
Employee emp = new Employee();
//拷贝的属性名跟类型必须一模一样
BeanUtils.copyProperties(employeeDTO,emp);
emp.setStatus(StatusConstant.ENABLE);
//设置默认密码为123456,并进行加密
emp.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
emp.setCreateTime(LocalDateTime.now());
emp.setUpdateTime(LocalDateTime.now());
//TODO 后面需要动态回去登录用户的ID
emp.setCreateUser(1L);
emp.setUpdateUser(1L);
//2.3 保存
employeeMapper.save(employee);

employeeMapper.save(employee). 方法需要传的参数应该是emp,写到这里的时候,突然头脑发昏,眼前一黑,就写错了,把它修改成emp,就能解决了.