Page.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (c) 2011-2014, hubin (jobob@qq.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. * <p>
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.baomidou.mybatisplus.plugins;
  17. import java.util.Collections;
  18. import java.util.List;
  19. import java.util.Map;
  20. import com.baomidou.mybatisplus.plugins.pagination.Pagination;
  21. /**
  22. * <p>
  23. * 实现分页辅助类
  24. * </p>
  25. *
  26. * @author hubin
  27. * @Date 2016-03-01
  28. */
  29. public class Page<T> extends Pagination {
  30. private static final long serialVersionUID = 1L;
  31. /**
  32. * 查询数据列表
  33. */
  34. private List<T> records = Collections.emptyList();
  35. /**
  36. * 查询参数
  37. */
  38. private transient Map<String, Object> condition;
  39. public Page() {
  40. /* 注意,传入翻页参数 */
  41. }
  42. public Page(int current, int size) {
  43. super(current, size);
  44. }
  45. public Page(int current, int size, String orderByField) {
  46. super(current, size);
  47. this.setOrderByField(orderByField);
  48. }
  49. public Page(int current, int size, String orderByField, boolean isAsc) {
  50. this(current, size, orderByField);
  51. this.setAsc(isAsc);
  52. }
  53. public List<T> getRecords() {
  54. return records;
  55. }
  56. public Page<T> setRecords(List<T> records) {
  57. this.records = records;
  58. return this;
  59. }
  60. public Map<String, Object> getCondition() {
  61. return condition;
  62. }
  63. public Page<T> setCondition(Map<String, Object> condition) {
  64. this.condition = condition;
  65. return this;
  66. }
  67. @Override
  68. public String toString() {
  69. StringBuilder pg = new StringBuilder();
  70. pg.append(" Page:{ [").append(super.toString()).append("], ");
  71. if (records != null) {
  72. pg.append("records-size:").append(records.size());
  73. } else {
  74. pg.append("records is null");
  75. }
  76. return pg.append(" }").toString();
  77. }
  78. }