All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.xiaoyuge5201.request.ResponseResult Maven / Gradle / Ivy
package com.github.xiaoyuge5201.request;
import java.util.HashMap;
/**
* 针对Layer 表格使用
* @author xiaoyuge
*/
public class ResponseResult extends HashMap {
private static final long serialVersionUID = 7180223617796870230L;
public static final int STATUS_OK = 200;
public static final int STATUS_FAIL = 500;
public static final int SERVER_CODE_OK = 0;
public static final String SERVER_MSG_OK = "success";
public static final int SERVER_CODE_FAIL = 1;
public static final String SERVER_MSG_FAIL = "fail";
private ResponseResult(int code, int status, String msg, Object data, int count) {
this(code, status, msg);
this.put("data", data);
this.put("count", count);
}
private ResponseResult(int code, int status, String msg, Object data) {
this(code, status, msg);
this.put("data", data);
}
public ResponseResult(int code, int status, String msg) {
this.put("code", code);
this.put("status", status);
this.put("msg", msg);
}
public ResponseResult(int code, String msg) {
this.put("code", code);
this.put("msg", msg);
}
@Override
public ResponseResult put(String key, Object value) {
super.put(key, value);
return this;
}
/**
* 接口返回数据成功---分页
*
* @param data
* @param totalCount
* @return
*/
public static ResponseResult success(Object data, Integer totalCount) {
return new ResponseResult(SERVER_CODE_OK, STATUS_OK, SERVER_MSG_OK, data, totalCount);
}
/**
* 接口返回数据成功---分页
*
* @param data
* @return
*/
public static ResponseResult success(Object data) {
return new ResponseResult(SERVER_CODE_OK, STATUS_OK, SERVER_MSG_OK, data);
}
/**
* 接口返回数据成功---分页
*
* @return
*/
public static ResponseResult success() {
return new ResponseResult(SERVER_CODE_OK, STATUS_OK, SERVER_MSG_OK);
}
/**
* 接口返回数据失败
*
* @return
*/
public static ResponseResult fail() {
return new ResponseResult(SERVER_CODE_FAIL, STATUS_FAIL, SERVER_MSG_FAIL);
}
/**
* 接口返回数据失败
*
* @return
*/
public static ResponseResult jsonFail() {
return new ResponseResult(STATUS_FAIL, SERVER_MSG_FAIL);
}
/**
* 异步请求返回数据结构
*
* @return
*/
public static ResponseResult jsonSuccess() {
return new ResponseResult(STATUS_OK, SERVER_MSG_OK);
}
/**
* 接口返回数据失败
*
* @param msg
* @return
*/
public static ResponseResult fail(String msg) {
return new ResponseResult(SERVER_CODE_FAIL, STATUS_FAIL, msg);
}
}