Result.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.goafanti.common.bo;
  2. import org.apache.shiro.SecurityUtils;
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. /**
  7. *
  8. * @param <T> 在Controller里面设置返回对象就可以用apipost读取到
  9. */
  10. public class Result<T> {
  11. private T data;
  12. private List<Error> error = new ArrayList<Error>();
  13. private String token;
  14. public Result() {
  15. this.token = (String) SecurityUtils.getSubject().getSession().getId();
  16. }
  17. public Result(T data) {
  18. this.data = data;
  19. }
  20. /**
  21. * @return the data
  22. */
  23. public T getData() {
  24. return data;
  25. }
  26. /**
  27. * @param data
  28. * the data to set
  29. */
  30. public void setData(T data) {
  31. this.data = data;
  32. }
  33. /**
  34. * @return the error
  35. */
  36. public List<Error> getError() {
  37. return error;
  38. }
  39. /**
  40. * @param error
  41. * the error to set
  42. */
  43. public void setError(List<Error> error) {
  44. this.error = error;
  45. }
  46. public Result<T> error(Error e) {
  47. if (e != null) {
  48. this.error.add(e);
  49. }
  50. return this;
  51. }
  52. public Result<T> data(T o) {
  53. this.data = o;
  54. return this;
  55. }
  56. public Serializable getToken() {
  57. return token;
  58. }
  59. public void setToken(String token) {
  60. this.token = token;
  61. }
  62. }