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

com.github.quartzwebui.service.JSONResult Maven / Gradle / Ivy

The newest version!
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.github.quartzwebui.service;

import com.github.quartzwebui.utils.json.JSONUtils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author quxiucheng [[email protected]]
 */
public class JSONResult {

    /**
     * 返回结果code
     */
    private int resultCode;

    /**
     * 返回结果
     */
    private Object content;

    /**
     * 返回json结果-成功(1)
     */
    public static final int RESULT_CODE_SUCCESS = 1;

    /**
     * 返回json结果-失败(-1)
     */
    public static final int RESULT_CODE_ERROR = -1;

    public JSONResult(int resultCode, Object content) {
        this.resultCode = resultCode;
        this.content = content;
    }

    /**
     * 创建一个json结果
     * @param resultCode
     * @param content
     * @return
     */
    public static JSONResult build(int resultCode, Object content){
        return new JSONResult(resultCode, content);
    }

    public String json() {
        Map dataMap = new LinkedHashMap();
        dataMap.put("resultCode", this.resultCode);
        dataMap.put("content", this.content);
        return JSONUtils.toJSONString(dataMap);
    }


    public static String returnJSON(int resultCode, Object content) {
        Map dataMap = new LinkedHashMap();
        dataMap.put("resultCode", resultCode);
        dataMap.put("content", content);
        return JSONUtils.toJSONString(dataMap);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy