net.dreamlu.boot.result.Results Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lutool-boot Show documentation
Show all versions of lutool-boot Show documentation
An enhanced toolkit of Spring boot to simplify development.
The newest version!
package net.dreamlu.boot.result;
/**
* 结果集返回工具
*
* @author L.cm
*/
public class Results {
private final static int FAILURE = 0;
private final static int SUCCESS = 1;
/**
* 数据库操作结果
* @param status 数据库操作结果
* @param 泛型标记
* @return Result
*/
public static Result status(boolean status) {
return status ? Results.success() : Results.failure();
}
/**
* 成功-携带数据
* @param data 数据
* @param 泛型标记
* @return Result
*/
public static Result success(T data) {
return result(SUCCESS, "操作成功", data);
}
/**
* 返回成功
* @param 泛型标记
* @return Result
*/
public static Result success() {
return success(null);
}
/**
* 返回失败信息
* @param msg 失败信息
* @param 泛型标记
* @return Result
*/
public static Result failure(String msg) {
return result(FAILURE, msg);
}
/**
* 返回失败信息
* @param 泛型标记
* @return Result
*/
public static Result failure() {
return failure("操作失败");
}
private static Result result(int code, String msg) {
return result(code, msg, null);
}
private static Result result(int code, String msg, T data) {
Result result = new Result<>();
result.setCode(code);
result.setMsg(msg);
if (data != null) {
result.setData(data);
}
return result;
}
}