@Data是Lombok依赖的注解,用于自动生成get和set方法,没有这个依赖的话就用ptj插件或者Alt+Insert让idea自动生成
package com.kgc.libraryos.utils;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;
import java.util.HashMap;
import java.util.Map;
@Data
public class MapUtil<T>{
private Map<String,Object> map;
private String msg="";
private int code=0;
private T data;
private boolean success = true;
public MapUtil(){};
public MapUtil(T data){
this.map = new HashMap<>();
this.data = data;
setElement();
}
public MapUtil(String msg,boolean success,T data){
this.map = new HashMap<>();
this.msg = msg;
this.success = success;
this.data = data;
setElement();
}
public MapUtil(int code,String msg,boolean success,T data){
this.map = new HashMap<>();
this.code = code;
this.msg = msg;
this.success = success;
this.data = data;
setElement();
}
private void setElement(){
this.map.put("code",this.code);
this.map.put("msg",this.msg);
this.map.put("success",this.success);
this.map.put("data",this.data);
}
public void putMap(String key,Object value){
this.map.put(key,value);
}
public void setMsg(String msg){
this.msg = msg;
this.map.put("msg",msg);
}
public void setSuccess(boolean success){
this.success = success;
this.map.put("success",success);
}
public void setData(T data){
this.data = data;
map.put("data",data);
}
}