importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importcom.szpl.gtkj.util.JsonUtil;public classResult {public static final String SUCCESS = "操作成功。";public static final String FAILURE = "操作失败!";private booleanresult;privateString msg;privateObject datas;privateResult() {}public staticResult ok() {returnResult.ok(SUCCESS);
}public staticResult ok(String msg) {return Result.ok(msg, null);
}public staticResult ok(Object datas) {returnResult.ok(SUCCESS, datas);
}public staticResult ok(String msg, Object datas) {
Result result= newResult();
result.setResult(true);
result.setMsg(msg);
result.setDatas(datas);returnresult;
}public staticResult fail() {returnResult.fail(FAILURE);
}public staticResult fail(String msg) {return Result.fail(msg, null);
}public staticResult fail(Object datas) {returnResult.fail(FAILURE, datas);
}public staticResult fail(String msg, Object datas) {
Result result= newResult();
result.setResult(false);
result.setMsg(msg);
result.setDatas(datas);returnresult;
}public booleanisResult() {returnresult;
}public void setResult(booleanresult) {this.result =result;
}publicString getMsg() {returnmsg;
}public voidsetMsg(String msg) {this.msg =msg;
}publicObject getDatas() {returndatas;
}public voidsetDatas(Object datas) {this.datas =datas;
}public static voidmain(String[] args) {
System.out.println(JsonUtil.obj2String(Result.ok()));
System.out.println(JsonUtil.obj2String(Result.ok("haha")));
System.out.println(JsonUtil.obj2String(Result.ok("haha", "aaa")));
Map map = new HashMap();
map.put("aa", "111");
map.put("bb", "22");
map.put("ccc", "33");
System.out.println(JsonUtil.obj2String(Result.ok("haha", map)));
List list = new ArrayList();
list.add("aaaaaaaa");
list.add("bbbbbb");
list.add("cccccccccccc");
list.add("ddddddddddd");
System.out.println(JsonUtil.obj2String(Result.ok("haha", list)));
System.out.println(JsonUtil.obj2String(Result.fail()));
System.out.println(JsonUtil.obj2String(Result.fail("失败了")));
System.out.println(JsonUtil.obj2String(Result.fail(list)));
System.out.println(JsonUtil.obj2String(Result.fail("失败了", map)));
}
}