智慧水务管理系统 - 精河县供水工程综合管理平台

BaseController.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package com.water.common.controller;
  2. import com.water.common.entity.R;
  3. import com.water.common.entity.query.PageQuery;
  4. import com.water.common.entity.query.PageResult;
  5. import com.water.common.entity.query.QueryCondition;
  6. import java.util.List;
  7. import java.util.Map;
  8. /**
  9. * 基础控制器
  10. */
  11. public abstract class BaseController<T> {
  12. /**
  13. * 成功响应
  14. */
  15. protected R<T> success(T data) {
  16. return R.success(data);
  17. }
  18. /**
  19. * 成功响应
  20. */
  21. protected R<T> success(String message, T data) {
  22. return R.success(message, data);
  23. }
  24. /**
  25. * 成功响应
  26. */
  27. protected R<Void> success() {
  28. return R.success();
  29. }
  30. /**
  31. * 成功响应
  32. */
  33. protected R<Void> success(String message) {
  34. return R.success(message);
  35. }
  36. /**
  37. * 失败响应
  38. */
  39. protected R<Void> error(String message) {
  40. return R.error(message);
  41. }
  42. /**
  43. * 失败响应
  44. */
  45. protected R<Void> error(int code, String message) {
  46. return R.error(code, message);
  47. }
  48. /**
  49. * 分页响应
  50. */
  51. protected R<PageResult<T>> page(PageResult<T> pageResult) {
  52. return success(pageResult);
  53. }
  54. /**
  55. * 列表响应
  56. */
  57. protected R<List<T>> list(List<T> list) {
  58. return success(list);
  59. }
  60. /**
  61. * 映射响应
  62. */
  63. protected R<Map<String, Object>> map(Map<String, Object> map) {
  64. return success(map);
  65. }
  66. /**
  67. * 验证查询条件
  68. */
  69. protected void validateQueryCondition(QueryCondition queryCondition) {
  70. if (queryCondition == null) {
  71. throw new IllegalArgumentException("查询条件不能为空");
  72. }
  73. PageQuery page = queryCondition.getPage();
  74. if (page == null) {
  75. page = new PageQuery();
  76. queryCondition.setPage(page);
  77. }
  78. if (page.getCurrent() == null || page.getCurrent() < 1) {
  79. page.setCurrent(1);
  80. }
  81. if (page.getSize() == null || page.getSize() < 1) {
  82. page.setSize(10);
  83. }
  84. if (page.getSize() > 1000) {
  85. throw new IllegalArgumentException("每页数量不能超过1000");
  86. }
  87. }
  88. }