JAVA 接口返回JSON格式转换类
使用了Lombok插件
Result.java
package com.utils; import com.jetsum.business.common.constant.Constant; import lombok.Data; import org.apache.commons.lang3.StringUtils; @Data public class Result<T> { private Integer code; private String msg; private String message; private T data; public Result ok(T t){ this.setCode(1000); this.setMsg("成功"); this.setMessage("成功"); this.setData(t); return this; } public Result fail(String msg){ this.setCode(1001); this.setMsg(msg); this.setMessage(msg); return this; } public Result() { } public Result(Integer code, String msg) { this.code = code; this.msg = msg; this.setMessage(msg); } public Result(Integer code, String msg, T data) { this.code = code; this.msg = msg; this.data = data; this.setMessage(msg); } }
使用方式
return new Result().ok(data);
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)