公用类 Result(返回结果集) PageResult(分页集) StatusCode(接口状态码) MyException(异常捕获) IdWorker(雪花算法)

Result(返回结果集)

package entity;

import java.io.Serializable;

public class Result implements Serializable {
	
    private boolean flag;//是否成功
    private Integer code;// 返回码
    private String message;//返回信息
    private Object data;// 返回数据

	public Result(boolean flag, Integer code, String message, Object data) {
		super();
		this.flag = flag;
		this.code = code;
		this.message = message;
		this.data = data;
	}

    public Result() {
    }
  
	public Result(boolean flag, Integer code, String message) {
		super();
		this.flag = flag;
		this.code = code;
		this.message = message;
	}
	public static Result error(String message){
		return new Result(false, StatusCode.ERROR, message,null);
	}

	public static Result success(String message){
		return new Result(true, StatusCode.OK, message,null);
	}
	public static Result success(String message,Object obj){
		return new Result(true, StatusCode.OK, message,obj);
	}
	
	public boolean isFlag() {
		return flag;
	}
	public void setFlag(boolean flag) {
		this.flag = flag;
	}
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	
	
}

PageResult(分页集)

package entity;

import java.io.Serializable;
import java.util.List;

//分页结果封装
public class PageResult<T> implements Serializable {

    private Long total;     //总页数
    private List<T> rows;  //数据集

    public PageResult(Long total, List<T> rows) {
        this.total = total;
        this.rows = rows;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }
}

StatusCode(接口状态码)

package entity;

public interface StatusCode {
     static final int OK=20000;//成功
     static final int ERROR =20001;//失败
     static final int LOGINERROR =20002;//用户名或密码错误
     static final int ACCESSERROR =20003;//权限不足
     static final int REMOTEERROR =20004;//远程调用失败
     static final int REPERROR =20005;//重复操作
}

MyException(异常捕获)

package exception;

//自定义异常处理,终止已知不符合业务逻辑的操作的继续执行

public class MyException extends RuntimeException{

    public MyException(String message){
        super(message);
    }
}

IdWorker(雪花算法)

公用类 Result(返回结果集) PageResult(分页集) StatusCode(接口状态码) MyException(异常捕获) IdWorker(雪花算法)_第1张图片

你可能感兴趣的:(公用类 Result(返回结果集) PageResult(分页集) StatusCode(接口状态码) MyException(异常捕获) IdWorker(雪花算法))