repo init

This commit is contained in:
ivmiku
2024-08-03 20:30:51 +08:00
commit dc534d7ee6
32 changed files with 1321 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
package com.ivmiku.tutorial.response;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable {
@JSONField(ordinal = 1)
private int code;
@JSONField(ordinal = 2)
private String message;
@JSONField(ordinal = 3)
private Object data = null;
public Result(ResultCode resultCode) {
this.code = resultCode.getCode();
this.message = resultCode.getMessage();
}
public Result(ResultCode resultCode, Object data) {
this.code = resultCode.getCode();
this.message = resultCode.getMessage();
this.data = data;
}
public static Result ok(){
return new Result(200, "success", null);
}
public static Result error(){
return new Result(-1, "error", null);
}
public static Result ok(Object data){
return new Result(200, "success", data);
}
public static Result ok(String message){
return new Result(200, message, null);
}
public static Result error(String message){
return new Result(-1, message, null);
}
}

View File

@@ -0,0 +1,17 @@
package com.ivmiku.tutorial.response;
import lombok.Getter;
@Getter
public enum ResultCode {
OK(200, "success"),
ERROR(-1, "error");
private int code;
private String message;
ResultCode(int code, String message) {
this.code = code;
this.message = message;
}
}