All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mycomm.itool.utils.R Maven / Gradle / Ivy

The newest version!
package com.mycomm.itool.utils;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author jw362j
 */
public class R extends HashMap {

	private static final long serialVersionUID = 1L;

	public R() {
		put("code", 0);
		put("msg", "success");
	}
	public R(boolean useless) {

	}

	public static R error() {
		return error(500, "未知异常,请联系管理员");
	}

	public static R error(String msg) {
		return error(500, msg);
	}

	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}
	public static R error(String code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}

	public static R ok(Map map) {
		R r = new R();
		r.putAll(map);
		return r;
	}

	public static R ok() {
		return new R();
	}

	public static R ok(boolean useless) {
		return new R(useless);
	}

	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}

	public R putCodeMsg(String code, Object msg) {
		super.put("code", code);
		super.put("msg", msg);
		return this;
	}

	/**
	 * (手动添加的)
	 *
	 * @return
	 */
	public Integer getCode() {
		return (Integer) this.get("code");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy