woshi

Posted symind

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了woshi相关的知识,希望对你有一定的参考价值。

package top.symind.base;

/**
* API 格式封装
* @author coder
*
*/
public class ApiResponse {
    private int code;
    private String message;
    private Object data;
    private boolean more;
    
    public ApiResponse(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    public ApiResponse() {
        this.code = Status.SUCCESS.getCode();
        this.message = Status.SUCCESS.getStandardMessage();
    }
    
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Object getData() {
        return data;
    }
    public void setData(Object data) {
        this.data = data;
    }
    public boolean isMore() {
        return more;
    }
    public void setMore(boolean more) {
        this.more = more;
    }
    
    public static ApiResponse ofMessage(int code, String message) {
        return new ApiResponse(code, message, null);
    }
    
    public static ApiResponse ofSuccess(Object data) {
        return new ApiResponse(Status.SUCCESS.getCode(), Status.SUCCESS.getStandardMessage(), data);
    }
    
    public static ApiResponse ofStatus(Status status) {
        return new ApiResponse(status.getCode(), status.getStandardMessage(), null);
    }
    
    public enum Status {
        SUCCESS(200, "OK"),
        BAD_REQUEST(400, "Bad Request"),
        NOT_FOUND(404, ""),
        INTERNAL_SERVER_ERROR(500, "Unknown Internal Error"),
        NOT_VALID_PARAM(40005, "Not Valid Params"),
        NOT_SUPPORTED_OPERATION(40006, "Operration Not Support"),
        NOT_LOGIN(50000, "Not Login");
        
        private int code;
        private String standardMessage;
        
        Status(int code, String standardMessage) {
            this.code = code;
            this.standardMessage = standardMessage;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getStandardMessage() {
            return standardMessage;
        }

        public void setStandardMessage(String standardMessage) {
            this.standardMessage = standardMessage;
        }
        
    }
}

以上是关于woshi的主要内容,如果未能解决你的问题,请参考以下文章

编译时处理Annotation 的一份代码

Oracle 语句如何转义

c语言 如何实现字符串由右向左读取且删除指定字符之前的所有字符?

Response下载文件

Ansible 模块使用

poj 1947 树形背包