封装类-统一接口返回结果



import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResponseMessage {

private int code;

private String msg;

private String description;

private Object data;

public ResponseMessage(int code, String msg) {
this.code = code;
this.msg = msg;
}

public static ResponseMessage successMessage(String message) {
return new ResponseMessage(200, "success", message, null);
}
public static ResponseMessage successMessage(String description, Object data) {
return new ResponseMessage(200, "success", description, data);
}
public static ResponseMessage successMessage(Object data) {
return new ResponseMessage(200, "success", null, data);
}

public static ResponseMessage failedMessage(String message) {
return new ResponseMessage(1, "failed", message, null);
}

public static ResponseMessage failedMessage(String message, Object data) {
return new ResponseMessage(1, "failed", message, data);
}

public static ResponseMessage permissionMessage(Object data) {
return new ResponseMessage(2, "permission denied", null, data);
}

public static ResponseMessage needLoginMessage() {
return new ResponseMessage(10, "need login");
}

public static ResponseMessage illegalMessage(String message) {
return new ResponseMessage(3, "illegal", message, null);
}

}
posted @ 2021-04-06 14:32  小叶子leavescy  阅读(178)  评论(0编辑  收藏  举报