统一返回类

@NoArgsConstructor
@Data
@Tag(name = "Json数据")
public class R<T> {



        /**
         * 状态码
         */
        @Schema(description = "状态码")
        private int code;

        /**
         * 提示信息
         */
        @Schema(description = "提示信息")
        private String msg;

        /**
         * 数据
         */
        @Schema(description = "数据")
        private T data;

        /**
         * 数据总数
         */
        @Schema(description = "数据总数")
        private int count;

        private R(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        private R(int code, String msg, T data) {
            this.code = code;
            this.msg = msg;
            this.data = data;
        }

        private R(int code, String msg, T data, int count) {
            this.code = code;
            this.msg = msg;
            this.data = data;
            this.count = count;
        }

        public static R ok(int code, String msg){
            R resultMap=new R(code,msg);

            return resultMap;
        }

        public static <T> R ok(int code, String msg, T data){
            R resultMap=new R(code,msg,data);

            return resultMap;
        }

        public static <T> R ok(int code, String msg, T data, int count){
            R resultMap=new R(code,msg,data,count);

            return resultMap;
        }

        public static R fail(int code, String msg){
            R resultMap=new R(code,msg);

            return resultMap;
        }

        public static <T> R fail(int code, String msg, T data){
            R resultMap=new R(code,msg,data);

            return resultMap;
        }

        public static <T> R fail(int code, String msg, T data, int count) {
            R resultMap = new R(code, msg, data, count);

            return resultMap;
        }
}

posted @ 2023-03-16 16:55  JacketLi  阅读(22)  评论(0编辑  收藏  举报