需要用到vo类
业务思路:
- 判断有无字段空或不合法
- 执行更新操作
之前在doLogin也使用过判断并显示错误信息
public GraceJSONResult updateUserInfo(UpdateUserBO updateUserBO, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
Map<String, String> bindResultErrors = getBindResultErrors(bindingResult);
return GraceJSONResult.errorMap(bindResultErrors);
}
userService.updateUserInfo(updateUserBO);
return GraceJSONResult.ok();
}
BO类 没什么好说的
public class UpdateUserBO {
@NotBlank(message = "用户不能Id为空")
private String id;
@NotBlank(message = "城市不能为空")
private String city;
@NotBlank(message = "地区不能为空")
private String district;
@NotBlank(message = "email不能为空")
@Email
private String email;
@NotBlank(message = "头像不能为空")
private String face;
@NotBlank(message = "用户名不能为空")
@Length(max = 12)
private String nickname;
@NotBlank(message = "省份不能为空")
private String province;
@NotBlank(message = "真实姓名不能为空")
private String realname;
@NotNull
@Min(value = 0, message = "性别选择错误")
@Max(value = 1, message = "性别选择错误")
private Integer sex;
@NotNull
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
private Date birthday;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFace() {
return face;
}
public void setFace(String face) {
this.face = face;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
service补全用户信息后 将用户状态修改为激活 然后进行更新操作 如果修改字段条数 != 1 表示修改失败
@Override
@Transactional
public void updateUserInfo(UpdateUserBO updateUserBO) {
AppUser user = new AppUser();
BeanUtils.copyProperties(updateUserBO, user);
user.setActiveStatus(UserStatus.ACTIVE.type);
int resultNum = userMapper.updateById(user);
if (resultNum != 1) {
GraceException.display(ResponseStatusEnum.USER_UPDATE_ERROR);
}
}