码迷,mamicode.com
首页 > 编程语言 > 详细

java返回实体类

时间:2021-04-01 13:39:00      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:turn   zab   final   mem   返回   class   author   long   dem   

package com.demo.common.beans;

import lombok.Data;

import java.io.Serializable;

/**
* @author zys
*/
@Data
public class ResultJson<T> 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 <T> ResultJson<T> ok(T data){
ResultBean<T> 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;
}
}

java返回实体类

标签:turn   zab   final   mem   返回   class   author   long   dem   

原文地址:https://www.cnblogs.com/zysnba/p/14604731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!