Java版
Result.java
import lombok.Data;
@Data
public class Result<T> {
private Integer code;
private String msg;
private T data;
public Result(ResultEnum resultEnum) {
this.code = resultEnum.getCode();
this.msg = resultEnum.getMsg();
}
public Result(ResultEnum resultEnum,T data) {
this(resultEnum);
this.data = data;
}
}
ResultEnum.java
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ResultEnum {
SUCCESS(200,"成功"),
FAIL(500,"失败"),
;
private final Integer code;
private final String msg;
}
ResultUtil.java