导读


一个模块建立一个VO类,通常市VO类有一个或者多条属性,但由于业务需要,对象属性值为null时,不返回该对象属性。

使用


在属性上添加注解 @JsonInclude(JsonInclude.Include.NON_NULL)

  1. import com.fasterxml.jackson.annotation.JsonInclude;
  2. import java.io.Serializable;
  3. /**
  4. * 返回前端VO类
  5. * @create 2020/1/2 16:35
  6. */
  7. public class OfficeVisualVO implements Serializable {
  8. private static final long serialVersionUID = -3989544016686250349L;
  9. /**
  10. * ---username
  11. */
  12. @JsonInclude(JsonInclude.Include.NON_NULL)
  13. private String username;
  14. /**
  15. * --age
  16. */
  17. @JsonInclude(JsonInclude.Include.NON_NULL)
  18. private String age;
  19. /**
  20. * --deptName
  21. */
  22. @JsonInclude(JsonInclude.Include.NON_NULL)
  23. private String deptName;
  24. /**
  25. * --deptNum
  26. */
  27. @JsonInclude(JsonInclude.Include.NON_NULL)
  28. private String deptNum;
  29. public String getDeptName() {
  30. return deptName;
  31. }
  32. public void setDeptName(String deptName) {
  33. this.deptName = deptName;
  34. }
  35. public String getUsername() {
  36. return username;
  37. }
  38. public void setUsername(String username) {
  39. this.username = username;
  40. }
  41. public String getAge() {
  42. return age;
  43. }
  44. public void setAge(String age) {
  45. this.age = age;
  46. }
  47. public String getDeptNum() {
  48. return deptNum;
  49. }
  50. public void setDeptNum(String deptNum) {
  51. this.deptNum = deptNum;
  52. }
  53. }