com.iqiny.silly.spring.controller.SillyR Maven / Gradle / Ivy
/*
* Copyright iqiny.com
*
* https://gitee.com/iqiny/silly
*
* project name:silly-spring
* project description:top silly project pom.xml file
*/
package com.iqiny.silly.spring.controller;
import java.util.TreeMap;
/**
* 返回数据
*/
public class SillyR extends TreeMap {
private static final long serialVersionUID = 1L;
public SillyR() {
put("code", 0);
put("success", true);
put("message", "success");
}
public static SillyR error() {
return error(500, "未知异常,请联系管理员");
}
public static SillyR error(String msg) {
return error(500, msg);
}
public static SillyR error(int code, String msg) {
SillyR r = new SillyR();
r.put("code", code);
r.put("message", msg);
r.put("success", false);
return r;
}
public static SillyR ok(String msg) {
SillyR r = new SillyR();
r.put("message", msg);
return r;
}
public static SillyR ok(Object obj) {
SillyR r = new SillyR();
r.put("data", obj);
return r;
}
public static SillyR ok(String msg, Object obj) {
SillyR r = new SillyR();
r.put("message", msg);
r.put("data", obj);
return r;
}
@Override
public SillyR put(String key, Object value) {
super.put(key, value);
return this;
}
}