java返回json格式的状态码数据(二)
生活随笔
收集整理的這篇文章主要介紹了
java返回json格式的状态码数据(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public interface CommonConstants {/*** 成功標記*/Integer SUCCESS = 0;/*** 失敗標記*/Integer FAIL = 1;}
public class R<T> implements Serializable {private static final long serialVersionUID = 1L;@Getter@Setter@ApiModelProperty(value = "返回操作碼 0成功 1失敗")private int code;@Getter@Setter@ApiModelProperty(value = "操作提示")private String msg;@Getter@Setter@ApiModelProperty(value = "返回數據")private T data;public static <T> R<T> ok() {return restResult(null, CommonConstants.SUCCESS, null);}public static <T> R<T> ok(T data) {return restResult(data, CommonConstants.SUCCESS, null);}public static <T> R<T> ok(T data, String msg) {return restResult(data, CommonConstants.SUCCESS, msg);}public static <T> R<T> failed() {return restResult(null, CommonConstants.FAIL, null);}public static <T> R<T> failed(String msg) {return restResult(null, CommonConstants.FAIL, msg);}public static <T> R<T> failed(T data) {return restResult(data, CommonConstants.FAIL, null);}public static <T> R<T> failed(T data, String msg) {return restResult(data, CommonConstants.FAIL, msg);}private static <T> R<T> restResult(T data, int code, String msg) {R<T> apiResult = new R<>();apiResult.setCode(code);apiResult.setData(data);apiResult.setMsg(msg);return apiResult;}
}
總結
以上是生活随笔為你收集整理的java返回json格式的状态码数据(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux下安装oracle 11g数据
- 下一篇: Apache seaTunnel的本地启