首页 > 其他 > 详细

返回值工具类

时间:2021-06-11 16:52:21      阅读:24      评论:0      收藏:0      [点我收藏+]
1.常量值
public interface ResultCode {

public static Integer SUCCESS = 20000;
public static Integer ERROR = 20001;
}



2.返回值类

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;

@Data
public class R {

@ApiModelProperty(value = "是否成功")

private Boolean success;


@ApiModelProperty(value = "返回码")

private Integer code;


@ApiModelProperty(value = "返回消息")

private String message;


@ApiModelProperty(value = "返回数据")

private java.util.Map<String, Object> data = new HashMap<String, Object>();


private R(){}


public static R ok(){

R r = new R();

r.setSuccess(true);

r.setCode(ResultCode.SUCCESS);

r.setMessage("成功");

return r;

}


public static R error(){

R r = new R();

r.setSuccess(false);

r.setCode(ResultCode.ERROR);

r.setMessage("失败");

return r;

}


public R success(Boolean success){

this.setSuccess(success);

return this;

}


public R message(String message){

this.setMessage(message);

return this;

}


public R code(Integer code){

this.setCode(code);

return this;

}


public R data(String key, Object value){

this.data.put(key, value);

return this;

}


public R data(java.util.Map<String, Object> map){

this.setData(map);

return this;

}

}

返回值工具类

原文:https://www.cnblogs.com/upupup-999/p/14875030.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!