com.lx.entity.Result Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lxboot3 Show documentation
Show all versions of lxboot3 Show documentation
使用文档: https://a7fi97h1rc.feishu.cn/docx/X3LRdtLhkoXQ8hxgXDQc2CLOnEg?from=from_copylink
package com.lx.entity;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lx.boot.OS;
import com.lx.constant.DefaultStatusCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* 结果
*
* @author ylx
* @date 2020-05-28
*/
@Data
@Schema(name = "响应实体类")
public class Result implements Serializable {
@Schema(description = "返回状态码",required = true)
//返回状态码
private Integer code;
@Schema(description = "返回信息",required = false)
//返回信息
private String message;
@Schema(description = "返回数据",required = false)
//返回数据
private T data;
@Schema(description = "日志流水号",required = false)
private String logTraceId = OS.getLogTraceId();
//说明: 发生错误
/**{ ylx } 2021/1/15 15:27 */
public boolean isErr(){
return DefaultStatusCode.OK != code;
}
/**
* 返回调用成功
*
* @return {@link Result}
*/
public static Result ok(){
return new Result(DefaultStatusCode.OK, "调用成功!");
}
/**
* 成功 返回 Data
*
* @param r r
* @return {@link Result}
*/
public static Result ok(R r){
return new Result(DefaultStatusCode.OK,r);
}
/** 说明: 返回分页
* @author ylx 2023/4/18 14:33 */
public static Result> ok(Page page){
return new Result(DefaultStatusCode.OK,new PageResult(page));
}
/**
* 调用成功返回提示信息 和 Data
*/
public static Result ok(String message,R r){
return new Result(DefaultStatusCode.OK,message, r);
}
/**
* 返回错误
*
* @param msg
* @return {@link Result}
*/
public static Result err(String msg){
return new Result(DefaultStatusCode.ERROR,msg);
}
/**
* 返回指定错误码 和 错误信息
*/
public static Result err(Integer code,String msg){
return new Result(code,msg);
}
/***
* Description 返回指定code码,错误信息,数据
* @author nq
* @CreateDate 2021/2/21 20:24
*/
public static Result err(Integer code,String msg,Object data){
return new Result(code,msg,data);
}
public Result() {}
public Result(Integer code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public Result(Integer code, T data) {
this.code = code;
this.data = data;
}
public Result(Integer code, String message) {
this.code = code;
this.message = message;
}
public Result(Integer code) {
this.code = code;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy