BaseRESTfulController.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.steerinfo.dil.util;
  2. import com.steerinfo.framework.controller.BaseController;
  3. import com.steerinfo.framework.controller.RESTfulResult;
  4. /**
  5. * @Author zhangnan
  6. * @Date 2021/7/8 11:33
  7. * @Version 1.0
  8. */
  9. public class BaseRESTfulController extends BaseController {
  10. public BaseRESTfulController() {
  11. }
  12. protected RESTfulResult success() {
  13. RESTfulResult result = new RESTfulResult();
  14. result.setSucceed();
  15. result.setMessage(result.getResultMessage());
  16. result.setData(true);
  17. result.setCode("200");
  18. return result;
  19. }
  20. protected RESTfulResult success(Object obj) {
  21. RESTfulResult result = new RESTfulResult();
  22. result.setSucceed();
  23. result.setMessage(result.getResultMessage());
  24. result.setData(obj);
  25. result.setCode("200");
  26. return result;
  27. }
  28. protected RESTfulResult success(Object obj, String msg) {
  29. RESTfulResult result = this.success(obj);
  30. result.setMessage(msg);
  31. result.setCode("200");
  32. return result;
  33. }
  34. protected RESTfulResult success(Object obj, String code, String msg) {
  35. RESTfulResult result = this.success(obj, msg);
  36. result.setCode("200");
  37. result.setCode(code);
  38. return result;
  39. }
  40. protected RESTfulResult failed() {
  41. return this.failed((Object) null);
  42. }
  43. protected RESTfulResult failed(Object obj) {
  44. RESTfulResult result = new RESTfulResult("201", (String) null);
  45. result.setMessage(result.getResultMessage());
  46. result.setData(obj);
  47. return result;
  48. }
  49. protected RESTfulResult failed(Object obj, String msg) {
  50. RESTfulResult result = new RESTfulResult("201", msg);
  51. result.setData(obj);
  52. return result;
  53. }
  54. protected RESTfulResult failed(Object obj, String code, String msg) {
  55. RESTfulResult result = this.failed(obj, msg);
  56. result = new RESTfulResult("201", msg);
  57. result.setCode(code);
  58. return result;
  59. }
  60. protected RESTfulResult loginFailed(String msg) {
  61. RESTfulResult result = new RESTfulResult("500", msg);
  62. return result;
  63. }
  64. }