首页>代码>springboot整合thymeleaf+layui实现简单的商品后台管理系统>/简单点JAVA架构/beliefframework/src/main/java/com/javaer/beliefframework/common/CommonResult.java
package com.javaer.beliefframework.common;

/**
 * 通用返回格式,使用泛型兼容 layui table
 *
 * */
public class CommonResult<T> {

    private long code;//状态码
    private String msg;//消息
    private long count;//返回数据的数量
    private T data;//数据

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

    /**
     * 静态工厂方法构造成功的CommonResult
     * @param count 数量
     * @param data 数据
     * */
    public static <T> CommonResult<T> generateSuccessResult(long count, T data){
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), count, data);
    }

    /**
     * 静态工厂方法构造成功的CommonResult,自定义消息
     * @param msg 成功提示信息
     * @param count 数量
     * @param data 数据
     * */
    public static <T> CommonResult<T> generateSuccessResult(String msg, long count, T data){
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), msg, count, data);
    }

    /**
     * 静态工厂方法构造失败的CommonResult
     * @param count 数量
     * @param data 数据
     * */
    public static <T> CommonResult<T> generateFailureResult(long count, T data){
        return new CommonResult<T>(ResultCode.FAILURE.getCode(), ResultCode.FAILURE.getMsg(), 0, null);
    }

    /**
     * 静态工厂方法构造失败的CommonResult,自定义消息
     * @param msg 成功提示信息
     * @param count 数量
     * @param data 数据
     * */
    public static <T> CommonResult<T> generateFailureResult(String msg, long count, T data){
        return new CommonResult<T>(ResultCode.FAILURE.getCode(), msg, 0, null);
    }

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
最近下载更多
hkxyyz  LV6 3月25日
f22m1a2b2  LV17 1月8日
lz88888  LV12 1月7日
ma406805131  LV19 2024年11月29日
zolscy  LV24 2024年11月26日
kaonixiwa  LV3 2024年10月30日
fei3655  LV6 2024年10月16日
y1214435276  LV9 2024年9月26日
微信网友_7134912998903808  LV15 2024年8月29日
599142776  LV2 2024年8月13日
最近浏览更多
hkxyyz  LV6 3月25日
zhangtian1997  LV10 2月5日
f22m1a2b2  LV17 1月8日
lz88888  LV12 1月7日
weishenme1993  LV9 1月1日
xinshou11111x 2024年12月12日
暂无贡献等级
haomc052829  LV4 2024年12月3日
kaonixiwa  LV3 2024年10月30日
fei3655  LV6 2024年10月16日
y1214435276  LV9 2024年9月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友