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

com.github.lhnonline.boot.common.response.PageResult Maven / Gradle / Ivy

Go to download

用于SpringBoot项目 | 接口返回数据包装,http状态码aop, http请求日志统一打印 | 使用了fastjson,和 mybatis-plus-extension

The newest version!
package com.github.lhnonline.boot.common.response;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.lhnonline.boot.common.util.HttpCode;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * author luohaonan
 * date 2020-11-11
 * email [email protected]
 * description
 */
@Getter
@Setter
@SuppressWarnings("all")
public class PageResult extends BaseResult {

    /**
     * 总记录条数
     */
    private Long total;

    protected PageResult(Integer code, Boolean success, String msg, T data, T error, Long total) {
        super(code, success, msg, data, error);
        setTotal(total);
    }

    public static PageResult fromMybatisPlusPage(IPage pageInfo) {
        long total = pageInfo.getTotal();
        List records = pageInfo.getRecords();
        return new PageResult(HttpCode.OK, true, null, records, null, total);
    }

    public static PageResult fromMybatisPlusPage(IPage pageInfo, String msg) {
        PageResult result = PageResult.fromMybatisPlusPage(pageInfo);
        result.setMsg(msg);
        return result;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy