Response.java 925 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.nju.edu.eval.web;
  2. import com.nju.edu.eval.exception.MyServiceException;
  3. import lombok.AllArgsConstructor;
  4. import lombok.Data;
  5. import lombok.NoArgsConstructor;
  6. import org.dom4j.util.AttributeHelper;
  7. import org.hibernate.service.spi.ServiceException;
  8. /**
  9. * @author mars
  10. */
  11. @Data
  12. @AllArgsConstructor
  13. @NoArgsConstructor
  14. public class Response {
  15. private String code;
  16. private String msg;
  17. private Object result;
  18. public Response(String code, String msg) {
  19. this.code = code;
  20. this.msg = msg;
  21. }
  22. public static Response buildSuccess(Object result) {
  23. return new Response("00000", "Success", result);
  24. }
  25. public static Response buildFailed(String code, ServiceException e) {
  26. return new Response(code, e.getLocalizedMessage(), null);
  27. }
  28. public static Response buildFailed(String code, String msg) {
  29. return new Response(code, msg, null);
  30. }
  31. }