一、创建Dto和ViewModel

image.png

  1. package com.yhh.common.entity.member.dto;
  2. import io.swagger.annotations.ApiModelProperty;
  3. import lombok.Data;
  4. import java.io.Serializable;
  5. import java.time.LocalDateTime;
  6. @Data
  7. public class UserDto implements Serializable {
  8. private Integer pageNum;
  9. private Integer pageSize;
  10. private Integer orderby;
  11. private Long id;
  12. private Integer status;
  13. private LocalDateTime createTime;
  14. private LocalDateTime modifyTime;
  15. private String phoneNumber;
  16. private String email;
  17. private String openId;
  18. private String password;
  19. private Integer sex;
  20. private String name;
  21. private Integer age;
  22. private String pic;
  23. private Integer isVip;
  24. private Integer score;
  25. }
  1. package com.yhh.common.entity.member.view;
  2. import com.yhh.common.entity.member.model.User;
  3. import io.swagger.annotations.ApiModel;
  4. import io.swagger.annotations.ApiModelProperty;
  5. import lombok.Data;
  6. import java.io.Serializable;
  7. import java.time.LocalDateTime;
  8. @Data
  9. @ApiModel(value = "UserView",description = "")
  10. public class UserView implements Serializable {
  11. public UserView() {
  12. }
  13. public UserView(User user){
  14. this.id = user.getId();
  15. this.status = user.getStatus();
  16. this.createTime = user.getCreateTime();
  17. this.modifyTime = user.getModifyTime();
  18. this.phoneNumber = user.getPhoneNumber();
  19. this.email = user.getEmail();
  20. this.openId = user.getOpenId();
  21. this.password = user.getPassword();
  22. this.sex = user.getSex();
  23. this.name = user.getName();
  24. this.age =user.getAge();
  25. this.pic = user.getPic();
  26. this.isVip = user.getIsVip();
  27. this.score = user.getScore();
  28. }
  29. @ApiModelProperty(value = "用户ID")
  30. private Long id;
  31. @ApiModelProperty(value = "使用状态(0:禁用 1:正常)")
  32. private Integer status;
  33. @ApiModelProperty(value = "创建时间")
  34. private LocalDateTime createTime;
  35. @ApiModelProperty(value = "修改时间")
  36. private LocalDateTime modifyTime;
  37. @ApiModelProperty(value = "电话号码")
  38. private String phoneNumber;
  39. @ApiModelProperty(value = "用户邮箱")
  40. private String email;
  41. @ApiModelProperty(value = "微信ID")
  42. private String openId;
  43. @ApiModelProperty(value = "用户密码")
  44. private String password;
  45. @ApiModelProperty(value = "用户性别(0:男 1:女)")
  46. private Integer sex;
  47. @ApiModelProperty(value = "用户性别:男/女)")
  48. private String strSex;
  49. public String getStrSex() {
  50. return this.sex == 0 ? "男":"女";
  51. }
  52. @ApiModelProperty(value = "用户名称")
  53. private String name;
  54. @ApiModelProperty(value = "用户年龄")
  55. private Integer age;
  56. @ApiModelProperty(value = "用户头像")
  57. private String pic;
  58. @ApiModelProperty(value = "是否是vip(0:普通用户 1:vip)")
  59. private Integer isVip;
  60. @ApiModelProperty(value = "用户积分")
  61. private Integer score;
  62. }

二、实现业务逻辑

2.1创建getByPage 服务接口

image.png

2.2 编写业务实现

image.png

2.3 控制器调用Business

image.png

三、编写过滤器

3.1 编写utils.FieldsFilter

image.png

3.2 MemberController调用过滤器

image.png