123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package com.fdkankan.common.base;
- import com.alibaba.fastjson.JSON;
- import org.springframework.stereotype.Component;
- import java.util.Map;
- @Component("jsonResult")
- public class JsonResult {
-
- private String VERSION = Config.VERSION;
- private Integer statusCode;
- private String statusMsg;
- private String version;
- private String token;
- private Object data;
-
- public JsonResult() {
- this.setVersion(VERSION);
- }
-
- public Integer getStatusCode() {
- return statusCode;
- }
- public void setStatusCode(Integer statusCode) {
- this.statusCode = statusCode;
- }
- public String getStatusMsg() {
- return statusMsg;
- }
- public void setStatusMsg(String statusMsg) {
- this.statusMsg = statusMsg;
- }
- public String getVersion() {
- return version;
- }
- public void setVersion(String version) {
- this.version = version;
- }
- public String getToken() {
- return token;
- }
- public void setToken(String token) {
- this.token = token;
- }
-
- public Object getData() {
- return data;
- }
- public void setData(Object data) {
- this.data = data;
- }
-
- public String ok() {
- return this.ok("");
- }
-
- public String ok(Object data) {
- return this.ok("", data);
- }
- public String ok(String msg, Object data) {
- return this.base(200, msg, data);
- }
-
- public String parameterError(String msg, Map<String, Object> paramMap) {
- return this.base(203, msg, paramMap);
- }
- public String error(int code, String msg) {
- return this.error(code, msg, "");
- }
-
- public String error(int code, String msg, Object data) {
- return this.base(code, msg, data);
- }
-
- public String noRecord() {
- return this.base(202, "没有记录 !!!");
- }
-
- public String notLoggedIn() {
- return this.base(201, " 请登录 !!!");
- }
- public String notLoggedIn(Object data) {
- return this.base(201, " 请登录 !!!", data);
- }
-
- public String noPower() {
- return this.base(206, "没有权限!!!");
- }
-
- private String base(int code, String msg) {
- return this.base(code, msg, "");
- }
-
- private String base(int code, String msg, Object data) {
- JsonResult jd = new JsonResult();
- jd.setStatusCode(code);
- jd.setStatusMsg(msg);
- jd.setData(data);
- return JSON.toJSONString(jd);
- }
-
- }
|