ApiResult.java
package com.dirk.demo.viewmodel;
public class ApiResult {
public ApiResult() {
this.code = 1;
this.timestamp = System.currentTimeMillis();
}
public ApiResult(Object data) {
this.code = 1;
this.data = data;
this.timestamp = System.currentTimeMillis();
}
private int code;
private long timestamp;
private Object data;
public static ApiResult ok() {
return new ApiResult();
}
public static ApiResult ok(Object data) {
return new ApiResult(data);
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
ApiError.java
package com.dirk.doorlock.viewmodel;
public class ApiError extends ApiResult {
public static int UN_LOGIN = -1;
public static int NOLoginId = -2;
public static int ErrorPassword = -3;
public static int FailUpload = -4;
private String message;
public ApiError(String message, int status) {
super();
setCode(status);
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public static ApiError unLogin() {
return new ApiError("未登陆", UN_LOGIN);
}
public static ApiError loginIdNotFound() {
return new ApiError("不存在的用户名", NOLoginId);
}
public static ApiError errorPassword() {
return new ApiError("密码错误", ErrorPassword);
}
public static ApiError failUpload(){
return new ApiError("上传失败",FailUpload);
}
}