java返回实体类

2021-04-02 00:28

阅读:295

package com.demo.common.beans;

import lombok.Data;

import java.io.Serializable;

/**
* @author zys
*/
@Data
public class ResultJson implements Serializable {

private static final long serialVersionUID = 1L;

public static final int SUCCESS = 0;

public static final int FAIL = 1;


private String msg = "success";

private int code = SUCCESS;

private long timestamp;

private T data;

public ResultJson() {
super();
}

public ResultJson(T data) {
super();
this.data = data;
this.timestamp = System.currentTimeMillis();
}

public ResultJson(Throwable e) {
super();
this.msg = e.toString();
this.code = FAIL;
}

public static ResultJson ok(T data){
ResultBean rj = new ResultBean();
rj.code = SUCCESS;
rj.msg = "success";
rj.timestamp = System.currentTimeMillis();
rj.data = data;
return rj;
}

public static ResultJson ok(){
ResultBean rj = new ResultBean();
rj.code = SUCCESS;
rj.msg = "success";
rj.timestamp = System.currentTimeMillis();
return rj;
}
public static ResultJson error(String msg){
ResultBean rj = new ResultBean();
rj.code = FAIL;
rj.msg = msg;
rj.timestamp = System.currentTimeMillis();
return rj;
}

public static ResultJson error(int code,String msg){
ResultBean rj = new ResultBean();
rj.code = code;
rj.msg = msg;
rj.timestamp = System.currentTimeMillis();
return rj;
}
}


评论


亲,登录后才可以留言!