MessageListBean.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.lqkj.link.message;
  2. import io.swagger.v3.oas.annotations.media.Schema;
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. /**
  7. * 服务器多个信息bean
  8. * Created by free on 2017/7/27 0027.
  9. */
  10. @Schema(description = "多个实体返回对象")
  11. public class MessageListBean<T> extends MessageBaseBean implements Serializable {
  12. public MessageListBean() {
  13. this.setTime(System.currentTimeMillis());
  14. }
  15. public MessageListBean(List<T> data) {
  16. this.data = data;
  17. this.setTime(System.currentTimeMillis());
  18. }
  19. /**
  20. * 被包含的多个消息实体
  21. */
  22. @Schema(description = "包含的对象")
  23. private List<T> data;
  24. public List<T> getData() {
  25. return data;
  26. }
  27. public void setData(List<T> data) {
  28. this.data = data;
  29. }
  30. /**
  31. * 增加一个数据
  32. *
  33. * @param data 数据
  34. */
  35. public void addData(T data) {
  36. if (this.data == null) {
  37. this.data = new ArrayList<T>(5);
  38. }
  39. this.data.add(data);
  40. }
  41. public static <T> MessageListBean<T> ok(List<T> data, String message) {
  42. MessageListBean<T> messageListBean = new MessageListBean<>();
  43. messageListBean.setStatus(true);
  44. messageListBean.setData(data);
  45. messageListBean.setCode(200);
  46. messageListBean.setMessage(message);
  47. return messageListBean;
  48. }
  49. public static <T> MessageListBean<T> error(String message) {
  50. MessageListBean<T> messageListBean = new MessageListBean<>();
  51. messageListBean.setStatus(false);
  52. messageListBean.setCode(-1);
  53. messageListBean.setMessage(message);
  54. return messageListBean;
  55. }
  56. }