cn.coder.struts.view.JSONMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of struts Show documentation
Show all versions of struts Show documentation
A simple, light Java WEB + ORM framework.
package cn.coder.struts.view;
import java.util.HashMap;
import java.util.Map;
import cn.coder.struts.wrapper.JSONWrapper;
public final class JSONMap {
private final HashMap data = new HashMap<>();
private final JSONWrapper wrapper = new JSONWrapper();
public static JSONMap success() {
return new JSONMap().put("success", true).put("errcode", 0).put("errmsg", "ok");
}
public static JSONMap error(int errcode, String errmsg) {
return new JSONMap().put("success", false).put("errcode", errcode).put("errmsg", errmsg);
}
public JSONMap put(String name, Object value) {
this.data.put(name, value);
return this;
}
public JSONMap putAll(Map values) {
this.data.putAll(values);
return this;
}
public void clear() {
this.data.clear();
}
@Override
public String toString() {
return wrapper.write(data);
}
}