Envelop.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.yihu.ehr.util.rest;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. /**
  7. * 信封对象,封装REST接口的返回值内容。包括:
  8. * - 页码
  9. * - 页大小
  10. * - 错误消息
  11. * - 错误代码
  12. * - 对象模型
  13. *
  14. * 信封对象的返回场景:
  15. * - API使用者确实无法访问返回头,即一些语言库无法处理HTTP的响应消息,这时候需要以这种形式提供返回值。
  16. * - API需要支持交叉域请求(通过JSONP)。
  17. *
  18. * @author llh
  19. */
  20. public class Envelop<T, J> implements Serializable{
  21. private static final long serialVersionUID = 2076324875575488461L;
  22. private boolean successFlg;
  23. private int pageSize = 15;
  24. private int currPage = 1;
  25. private int totalPage = 0;
  26. private int totalCount;
  27. private List<T> detailModelList = new ArrayList<>();
  28. private J obj = (J) new HashMap<>(0);
  29. private String errorMsg;
  30. private int errorCode;
  31. public boolean isSuccessFlg() {
  32. return successFlg;
  33. }
  34. public void setSuccessFlg(boolean successFlg) {
  35. this.successFlg = successFlg;
  36. }
  37. public int getPageSize() {
  38. return pageSize;
  39. }
  40. public void setPageSize(int pageSize) {
  41. this.pageSize = pageSize;
  42. }
  43. public int getCurrPage() {
  44. return currPage;
  45. }
  46. public void setCurrPage(int currPage) {
  47. this.currPage = currPage;
  48. }
  49. public int getTotalPage() {
  50. if(pageSize == 0){
  51. pageSize = 15;
  52. }
  53. if (totalCount % pageSize > 0) {
  54. totalPage = totalCount / pageSize + 1;
  55. } else {
  56. totalPage = totalCount / pageSize;
  57. }
  58. return totalPage;
  59. }
  60. public void setTotalPage(int totalPage) {
  61. this.totalPage = totalPage;
  62. }
  63. public int getTotalCount() {
  64. return totalCount;
  65. }
  66. public void setTotalCount(int totalCount) {
  67. this.totalCount = totalCount;
  68. }
  69. public List<T> getDetailModelList() {
  70. return detailModelList;
  71. }
  72. public void setDetailModelList(List<T> detailModelList) {
  73. this.detailModelList = detailModelList;
  74. }
  75. public J getObj() {
  76. return obj;
  77. }
  78. public void setObj(J obj) {
  79. this.obj = obj;
  80. }
  81. public String getErrorMsg() {
  82. return errorMsg;
  83. }
  84. public void setErrorMsg(String errorMsg) {
  85. this.errorMsg = errorMsg;
  86. }
  87. public int getErrorCode() {
  88. return errorCode;
  89. }
  90. public void setErrorCode(int errorCode) {
  91. this.errorCode = errorCode;
  92. }
  93. }