```
public class ToJson {
//状态码
private int code;
//状态描述
private String statu;
//使用map存放数据
private Map<String, Object> data = new HashMap<String, Object>();
//成功方法
public static ToJson getSuccess() {
ToJson toJson = new ToJson();
toJson.setCode(100);
toJson.setStatu("成功");
return toJson;
}
//失败方法
public static ToJson getFail() {
ToJson toJson = new ToJson();
toJson.setCode(200);
toJson.setStatu("失败");
return toJson;
}
//放入数据方法,并返回对象本身
public ToJson putMap(String key, Object value) {
this.getData().put(key, value);
return this;
}
//set、get方法
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getStatu() {
return statu;
}
public void setStatu(String statu) {
this.statu = statu;
}
public Map<String, Object> getData() {
return data;
}
public void setData(Map<String, Object> data) {
this.data = data;
}
}
```