VO (Value Object)
主要对应界面显示的数据对象。对于一个WEB页面,用一个VO对象对应整个界面的值。
简而言之 vo用于想前端展示数据
因为不是所以字段都需要被查出来的 createdTime 和 updateTime 就不需要查询出来 这时候就需要vo了
public class AppUserVO {
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
private String mobile;
private String nickname;
private String face;
private String realname;
private String email;
private Integer sex;
private Date birthday;
private String province;
private String city;
private String district;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getFace() {
return face;
}
public void setFace(String face) {
this.face = face;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
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;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
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;
}
}
业务思路:
首先根据userId将数据查出
之后在使用BeanUtils.copyProperties()方法将查出的数据根据字段复制的vo中 然后返回给前端即可
@Override
public GraceJSONResult getAccountInfo(String userId) {
if (StringUtils.isBlank(userId)) {
return GraceJSONResult.errorCustom(ResponseStatusEnum.UN_LOGIN);
}
AppUser appUser = userService.getUser(userId);
AppUserVO appUserVO = new AppUserVO();
BeanUtils.copyProperties(appUser, appUserVO);
return GraceJSONResult.ok(appUserVO);
}
getUser直接调用mybatis plus的crud方法根据逐渐查询即可
@Override
public AppUser getUser(String userId) {
return userMapper.selectById(userId);
}