74 lines
1.8 KiB
Java
74 lines
1.8 KiB
Java
|
|
package com.cdzy.common.model;
|
||
|
|
|
||
|
|
import com.cdzy.common.enums.Code;
|
||
|
|
import com.cdzy.common.enums.Message;
|
||
|
|
import lombok.Data;
|
||
|
|
|
||
|
|
import java.io.Serializable;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param <E> 响应数据的类型
|
||
|
|
* @author : attiya
|
||
|
|
* 响应结果类
|
||
|
|
*/
|
||
|
|
@Data
|
||
|
|
public class JsonResult<E> implements Serializable {
|
||
|
|
/**
|
||
|
|
* 状态码
|
||
|
|
*/
|
||
|
|
private Integer code;
|
||
|
|
/**
|
||
|
|
* 状态描述信息
|
||
|
|
*/
|
||
|
|
private String message;
|
||
|
|
/**
|
||
|
|
* 数据
|
||
|
|
*/
|
||
|
|
private E data;
|
||
|
|
|
||
|
|
public JsonResult() {
|
||
|
|
}
|
||
|
|
|
||
|
|
public JsonResult(Integer code, String message, E data) {
|
||
|
|
super();
|
||
|
|
this.code = code;
|
||
|
|
this.message = message;
|
||
|
|
this.data = data;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public String toString() {
|
||
|
|
return "{" +
|
||
|
|
"code=" + code +
|
||
|
|
", message='" + message + '\'' +
|
||
|
|
", data=" + data +
|
||
|
|
'}';
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public static JsonResult<Object> success (Object data) {
|
||
|
|
return new JsonResult<>(Code.SUCCESS, Message.SUCCESS,data);
|
||
|
|
}
|
||
|
|
public static JsonResult<Object> success (String msg) {
|
||
|
|
return new JsonResult<>(Code.SUCCESS, msg,null);
|
||
|
|
}
|
||
|
|
public static JsonResult<Object> success (String msg,Object data) {
|
||
|
|
return new JsonResult<>(Code.SUCCESS, msg, data);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static JsonResult<String> success () {
|
||
|
|
return new JsonResult<String>(Code.SUCCESS, Message.SUCCESS,null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static JsonResult<String> failed() {
|
||
|
|
return new JsonResult<String>(Code.FAILED, Message.FAILED,null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static JsonResult<String> failed(String msg) {
|
||
|
|
return new JsonResult<String>(Code.FAILED, msg,null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static JsonResult<Object> failed(String msg, Object data) {
|
||
|
|
return new JsonResult<>(Code.FAILED, msg, data);
|
||
|
|
}
|
||
|
|
}
|