All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.novareseller.boot.utils.ResponseUtils Maven / Gradle / Ivy

There is a newer version: 1.5.3.beta
Show newest version
package io.github.novareseller.boot.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.github.novareseller.boot.wrapper.ApiPageResponse;
import io.github.novareseller.boot.wrapper.ApiResponse;

import java.util.List;

/**
 * @author: Bowen huang
 * @date: 2021/04/29
 */
public class ResponseUtils {

    private static int retCode = 0;

    public static void setRetCode(int systemCode) {
        if (retCode != 0) {
            return;
        }
        retCode = systemCode;
    }


    public static  ApiResponse ok(T data) {
        ApiResponse response = new ApiResponse<>();
        response.setData(data);
        response.setRetCode(retCode);
        return response;
    }

    public static  ApiResponse error(int errCode, String message) {
        ApiResponse response = new ApiResponse<>();
        response.setErrCode(errCode);
        response.setMessage(message);
        response.setRetCode(retCode);
        return response;
    }

    public static  ApiResponse error(int errCode, T data, String message) {
        ApiResponse response = new ApiResponse<>();
        response.setErrCode(errCode);
        response.setMessage(message);
        response.setData(data);
        response.setRetCode(retCode);
        return response;
    }

    public static  ApiPageResponse> page(IPage iPage) {
        ApiPageResponse> response = new ApiPageResponse<>();
        response.setData(iPage.getRecords());
        response.setCurrent(iPage.getCurrent());
        response.setSize(iPage.getSize());
        response.setTotal(iPage.getTotal());
        response.setRetCode(retCode);
        return response;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy