天天看点

SB后端写接口 小规范 CommonResp 类

先定义一个 CommonResp 类:

SB后端写接口 小规范 CommonResp 类
SB后端写接口 小规范 CommonResp 类

package com.bihu.study.resp;

public class CommonResp<T> {
    /**
     * 业务上的成功和失败
     * */
    private boolean success = true;

    /***
     * 返回信息
     */
    private String message;

    /***
     * 返回泛型数据  自定义数据
     */
    private T content;

    public CommonResp() {
    }

    public CommonResp(boolean success, String message, T content) {
        this.success = success;
        this.message = message;
        this.content = content;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "CommonResp{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", content=" + content +
                '}';
    }
}      

View Code

注释写的明明白白了

然后我们直接跳过持久层 和 服务层 ,这里不说 控制器中这样写:

SB后端写接口 小规范 CommonResp 类
SB后端写接口 小规范 CommonResp 类