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

com.feingto.cloud.dto.WebResult Maven / Gradle / Ivy

There is a newer version: 2.3.5.RELEASE
Show newest version
package com.feingto.cloud.dto;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.feingto.cloud.kit.json.JSON;

import javax.servlet.http.HttpServletResponse;

/**
 * 控制器返回JSON对象封装
 *
 * @author longfei
 */
public class WebResult {
    public static ObjectNode success() {
        return JSON.JSONObject().put("success", true);
    }

    public static ObjectNode success(String msg) {
        return success().put("message", msg);
    }

    public static ObjectNode error(String msg) {
        return JSON.JSONObject().put("success", false).put("message", msg);
    }

    public static ObjectNode error(Exception e) {
        return error(e.getMessage());
    }

    public static ObjectNode internalServerError() {
        return error("Internal Server Error").put("code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    public static ObjectNode notAcceptable() {
        return error("Not Acceptable").put("code", HttpServletResponse.SC_NOT_ACCEPTABLE);
    }

    public static ObjectNode notFound() {
        return error("Not Found").put("code", HttpServletResponse.SC_NOT_FOUND);
    }

    public static ObjectNode badRequest() {
        return error("Bad Request").put("code", HttpServletResponse.SC_BAD_REQUEST);
    }

    public static ObjectNode unAuthorized() {
        return error("Unauthorized").put("code", HttpServletResponse.SC_UNAUTHORIZED);
    }

    public static ObjectNode forbidden() {
        return error("Forbidden").put("code", HttpServletResponse.SC_FORBIDDEN);
    }

    public static ObjectNode serviceUnavailable() {
        return error("Service Unavailable").put("code", HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy