update 调整返回类型为 R

This commit is contained in:
疯狂的狮子li
2022-01-29 11:48:41 +08:00
parent eb87229ee9
commit 53da7140c2
38 changed files with 412 additions and 460 deletions

View File

@ -1,6 +1,6 @@
package com.ruoyi.common.core.controller;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.StringUtils;
@ -15,29 +15,29 @@ public class BaseController {
/**
* 返回成功
*/
public AjaxResult<Void> success() {
return AjaxResult.success();
public R<Void> success() {
return R.ok();
}
/**
* 返回失败消息
*/
public AjaxResult<Void> error() {
return AjaxResult.error();
public R<Void> error() {
return R.fail();
}
/**
* 返回成功消息
*/
public AjaxResult<Void> success(String message) {
return AjaxResult.success(message);
public R<Void> success(String message) {
return R.ok(message);
}
/**
* 返回失败消息
*/
public AjaxResult<Void> error(String message) {
return AjaxResult.error(message);
public R<Void> error(String message) {
return R.fail(message);
}
/**
@ -46,8 +46,8 @@ public class BaseController {
* @param rows 影响行数
* @return 操作结果
*/
protected AjaxResult<Void> toAjax(int rows) {
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
protected R<Void> toAjax(int rows) {
return rows > 0 ? R.ok() : R.fail();
}
/**
@ -56,7 +56,7 @@ public class BaseController {
* @param result 结果
* @return 操作结果
*/
protected AjaxResult<Void> toAjax(boolean result) {
protected R<Void> toAjax(boolean result) {
return result ? success() : error();
}

View File

@ -1,132 +0,0 @@
package com.ruoyi.common.core.domain;
import cn.hutool.http.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 操作消息提醒
*
* @author Lion Li
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("请求响应对象")
public class AjaxResult<T> {
private static final long serialVersionUID = 1L;
/**
* 状态码
*/
@ApiModelProperty("消息状态码")
private int code;
/**
* 返回内容
*/
@ApiModelProperty("消息内容")
private String msg;
/**
* 数据对象
*/
@ApiModelProperty("数据对象")
private T data;
/**
* 初始化一个新创建的 AjaxResult 对象
*
* @param code 状态码
* @param msg 返回内容
*/
public AjaxResult(int code, String msg) {
this.code = code;
this.msg = msg;
}
/**
* 返回成功消息
*
* @return 成功消息
*/
public static AjaxResult<Void> success() {
return AjaxResult.success("操作成功");
}
/**
* 返回成功数据
*
* @return 成功消息
*/
public static <T> AjaxResult<T> success(T data) {
return AjaxResult.success("操作成功", data);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @return 成功消息
*/
public static AjaxResult<Void> success(String msg) {
return AjaxResult.success(msg, null);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 成功消息
*/
public static <T> AjaxResult<T> success(String msg, T data) {
return new AjaxResult<>(HttpStatus.HTTP_OK, msg, data);
}
/**
* 返回错误消息
*
* @return
*/
public static AjaxResult<Void> error() {
return AjaxResult.error("操作失败");
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult<Void> error(String msg) {
return AjaxResult.error(msg, null);
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static <T> AjaxResult<T> error(String msg, T data) {
return new AjaxResult<>(HttpStatus.HTTP_INTERNAL_ERROR, msg, data);
}
/**
* 返回错误消息
*
* @param code 状态码
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult<Void> error(int code, String msg) {
return new AjaxResult<>(code, msg, null);
}
}

View File

@ -0,0 +1,84 @@
package com.ruoyi.common.core.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 响应信息主体
*
* @author Lion Li
*/
@Data
@NoArgsConstructor
@ApiModel("请求响应对象")
public class R<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 成功
*/
public static final int SUCCESS = 200;
/**
* 失败
*/
public static final int FAIL = 500;
@ApiModelProperty("消息状态码")
private int code;
@ApiModelProperty("消息内容")
private String msg;
@ApiModelProperty("数据对象")
private T data;
public static <T> R<T> ok() {
return restResult(null, SUCCESS, null);
}
public static <T> R<T> ok(T data) {
return restResult(data, SUCCESS, null);
}
public static <T> R<T> ok(String msg) {
return restResult(null, SUCCESS, msg);
}
public static <T> R<T> ok(T data, String msg) {
return restResult(data, SUCCESS, msg);
}
public static <T> R<T> fail() {
return restResult(null, FAIL, null);
}
public static <T> R<T> fail(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> R<T> fail(T data) {
return restResult(data, FAIL, null);
}
public static <T> R<T> fail(T data, String msg) {
return restResult(data, FAIL, msg);
}
public static <T> R<T> fail(int code, String msg) {
return restResult(null, code, msg);
}
private static <T> R<T> restResult(T data, int code, String msg) {
R<T> r = new R<>();
r.setCode(code);
r.setData(data);
r.setMsg(msg);
return r;
}
}