v1.4.1
Parker 5 years ago
parent cd4417952f
commit 782ae755d2

@ -0,0 +1,107 @@
package org.opsli.common.api;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.http.HttpStatus;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @date 202051510:40:54
* @author Parker
*
* Feign
*
* @JsonProperty null
*
*/
public class ResultDto<T> implements Serializable {
/** Map 容器 */
private final Map<String,Object> resultMap = new HashMap<>(3);
/** 数据 */
@JsonProperty("data")
private T data;
public ResultDto(){
resultMap.put("success", true);
resultMap.put("code", HttpStatus.OK.value());
resultMap.put("msg", "操作成功");
}
/**
*
* @return
*/
public int getCode() {
return (int)resultMap.get("code");
}
/**
*
* @param code
*/
public void setCode(int code) {
resultMap.put("code", code);
}
/**
*
* @return
*/
public String getMsg() {
return (String)resultMap.get("msg");
}
/**
*
* @param msg
*/
public void setMsg(String msg) {//向json中添加属性在js中访问请调用data.msg
resultMap.put("msg", msg);
}
/**
*
* @return
*/
public boolean isSuccess() {
return (boolean)resultMap.get("success");
}
/**
*
* @param success
*/
public void setSuccess(boolean success) {
resultMap.put("success", success);
}
// ---------------------------------
/**
*
* @param value
* @return
*/
public ResultDto<T> put(T value) {
data = value;
return this;
}
/**
*
* @return
*/
public T get(){
return data;
}
}

@ -0,0 +1,96 @@
package org.opsli.common.api;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.http.HttpStatus;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Web
*
* @date 202051510:40:54
* @author Parker
*
*/
public class ResultVo extends HashMap<String,Object> implements Serializable {
public ResultVo(){
this.put("success", true);
this.put("code", HttpStatus.OK.value());
this.put("msg", "操作成功");
}
/** get/set
* msg :
* code :
* success :
* */
public String getMsg() {
return (String)this.get("msg");
}
public void setMsg(String msg) {//向json中添加属性在js中访问请调用data.msg
this.put("msg", msg);
}
public int getCode() {
return (int)this.get("code");
}
public void setCode(int code) {
this.put("code", code);
}
public boolean isSuccess() {
return (boolean)this.get("success");
}
public void setSuccess(boolean success) {
this.put("success", success);
}
// -------------------------------------------
@JsonIgnore//返回对象时忽略此属性
public static ResultVo success(String msg) {
ResultVo j = new ResultVo();
j.setMsg(msg);
return j;
}
@JsonIgnore//返回对象时忽略此属性
public static ResultVo error(String msg) {
ResultVo j = new ResultVo();
j.setSuccess(false);
j.setMsg(msg);
return j;
}
@JsonIgnore//返回对象时忽略此属性
public static ResultVo success(Map<String, Object> map) {
ResultVo restResponse = new ResultVo();
restResponse.putAll(map);
return restResponse;
}
@JsonIgnore//返回对象时忽略此属性
public static ResultVo success() {
return new ResultVo();
}
@Override
public ResultVo put(String key, Object value) {
super.put(key, value);
return this;
}
public ResultVo putMap(Map m) {
super.putAll(m);
return this;
}
}
Loading…
Cancel
Save