123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- package net.lab1024.smartadmin.common.domain;
- import net.lab1024.smartadmin.common.constant.ResponseCodeConst;
- /**
- * 返回类
- *
- * @param <T>
- * @author zhuoda
- */
- public class ResponseDTO<T> {
- protected Integer code;
- protected String msg;
- protected Boolean success;
- protected T data;
- public ResponseDTO() {
- }
- public ResponseDTO(ResponseCodeConst responseCodeConst, String msg) {
- this.code = responseCodeConst.getCode();
- this.msg = msg;
- this.success = responseCodeConst.isSuccess();
- }
- public ResponseDTO(ResponseCodeConst responseCodeConst, T data) {
- super();
- this.code = responseCodeConst.getCode();
- this.msg = responseCodeConst.getMsg();
- this.data = data;
- this.success = responseCodeConst.isSuccess();
- }
- public ResponseDTO(ResponseCodeConst responseCodeConst, T data, String msg) {
- super();
- this.code = responseCodeConst.getCode();
- this.msg = msg;
- this.data = data;
- this.success = responseCodeConst.isSuccess();
- }
- private ResponseDTO(ResponseCodeConst responseCodeConst) {
- this.code = responseCodeConst.getCode();
- this.msg = responseCodeConst.getMsg();
- this.success = responseCodeConst.isSuccess();
- }
- public ResponseDTO(ResponseDTO responseDTO) {
- this.code = responseDTO.getCode();
- this.msg = responseDTO.getMsg();
- this.success = responseDTO.isSuccess();
- }
- public static <T> ResponseDTO<T> succ() {
- return new ResponseDTO(ResponseCodeConst.SUCCESS);
- }
- public static <T> ResponseDTO<T> succData(T data, String msg) {
- return new ResponseDTO(ResponseCodeConst.SUCCESS, data, msg);
- }
- public static <T> ResponseDTO<T> succData(T data) {
- return new ResponseDTO(ResponseCodeConst.SUCCESS, data);
- }
- public static <T> ResponseDTO succMsg(String msg) {
- return new ResponseDTO(ResponseCodeConst.SUCCESS, msg);
- }
- public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst) {
- return new ResponseDTO<>(codeConst);
- }
- public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst, T t) {
- return new ResponseDTO<T>(codeConst, t);
- }
- public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst, String msg) {
- return new ResponseDTO<T>(codeConst, msg);
- }
- public String getMsg() {
- return msg;
- }
- public ResponseDTO setMsg(String msg) {
- this.msg = msg;
- return this;
- }
- public int getCode() {
- return code;
- }
- public ResponseDTO setCode(Integer code) {
- this.code = code;
- return this;
- }
- public T getData() {
- return data;
- }
- public ResponseDTO setData(T data) {
- this.data = data;
- return this;
- }
- public boolean isSuccess() {
- return success;
- }
- public void setSuccess(boolean success) {
- this.success = success;
- }
- @Override
- public String toString() {
- return "ResponseDTO{" + "code=" + code + ", msg='" + msg + '\'' + ", success=" + success + ", data=" + data +
- '}';
- }
- }
|