mall-admin代码改造
This commit is contained in:
@@ -11,7 +11,8 @@ import java.util.List;
|
||||
public class CommonPage<T> {
|
||||
private Integer pageNum;
|
||||
private Integer pageSize;
|
||||
private Long totalPage;
|
||||
private Integer totalPage;
|
||||
private Long total;
|
||||
private List<T> list;
|
||||
|
||||
/**
|
||||
@@ -20,9 +21,10 @@ public class CommonPage<T> {
|
||||
public static <T> CommonPage<T> restPage(List<T> list) {
|
||||
CommonPage<T> result = new CommonPage<T>();
|
||||
PageInfo<T> pageInfo = new PageInfo<T>(list);
|
||||
result.setTotalPage(pageInfo.getTotal() / pageInfo.getPageSize());
|
||||
result.setTotalPage(pageInfo.getPages());
|
||||
result.setPageNum(pageInfo.getPageNum());
|
||||
result.setPageSize(pageInfo.getPageSize());
|
||||
result.setTotal(pageInfo.getTotal());
|
||||
result.setList(pageInfo.getList());
|
||||
return result;
|
||||
}
|
||||
@@ -32,9 +34,10 @@ public class CommonPage<T> {
|
||||
*/
|
||||
public static <T> CommonPage<T> restPage(Page<T> pageInfo) {
|
||||
CommonPage<T> result = new CommonPage<T>();
|
||||
result.setTotalPage((long) pageInfo.getTotalPages());
|
||||
result.setTotalPage(pageInfo.getTotalPages());
|
||||
result.setPageNum(pageInfo.getNumber());
|
||||
result.setPageSize(pageInfo.getSize());
|
||||
result.setTotal(pageInfo.getTotalElements());
|
||||
result.setList(pageInfo.getContent());
|
||||
return result;
|
||||
}
|
||||
@@ -55,11 +58,11 @@ public class CommonPage<T> {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Long getTotalPage() {
|
||||
public Integer getTotalPage() {
|
||||
return totalPage;
|
||||
}
|
||||
|
||||
public void setTotalPage(Long totalPage) {
|
||||
public void setTotalPage(Integer totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
|
||||
@@ -70,4 +73,12 @@ public class CommonPage<T> {
|
||||
public void setList(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,88 +8,84 @@ public class CommonResult<T> {
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
protected CommonResult() {
|
||||
}
|
||||
|
||||
protected CommonResult(long code, String message, T data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通成功返回
|
||||
* 成功返回结果
|
||||
*
|
||||
* @param data 获取的数据
|
||||
*/
|
||||
public static <T> CommonResult<T> success(T data) {
|
||||
CommonResult<T> result = new CommonResult<T>();
|
||||
result.setCode(ResultCode.SUCCESS.getCode());
|
||||
result.setMessage(ResultCode.SUCCESS.getMsg());
|
||||
result.setData(data);
|
||||
return result;
|
||||
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通成功返回
|
||||
* 成功返回结果
|
||||
*
|
||||
* @param data 获取的数据
|
||||
* @param message 提示信息
|
||||
*/
|
||||
public static <T> CommonResult<T> success(T data,String message) {
|
||||
CommonResult<T> result = new CommonResult<T>();
|
||||
result.setCode(ResultCode.SUCCESS.getCode());
|
||||
result.setMessage(message);
|
||||
result.setData(data);
|
||||
return result;
|
||||
public static <T> CommonResult<T> success(T data, String message) {
|
||||
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过错误码对象构造返回结果
|
||||
* 失败返回结果
|
||||
* @param errorCode 错误码
|
||||
*/
|
||||
public static <T> CommonResult<T> failed(IErrorCode errorCode) {
|
||||
CommonResult<T> result = new CommonResult<T>();
|
||||
result.setCode(errorCode.getCode());
|
||||
result.setMessage(errorCode.getMsg());
|
||||
return result;
|
||||
return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通失败提示信息
|
||||
* 失败返回结果
|
||||
* @param message 提示信息
|
||||
*/
|
||||
public static <T> CommonResult<T> failed(String message) {
|
||||
CommonResult<T> result = new CommonResult<T>();
|
||||
result.setCode(ResultCode.FAILED.getCode());
|
||||
result.setMessage(message);
|
||||
return result;
|
||||
return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通操作失败
|
||||
* 失败返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> failed() {
|
||||
return failed(ResultCode.FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数验证失败使用
|
||||
* 参数验证失败返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> validateFailed() {
|
||||
return failed(ResultCode.VALIDATE_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数验证失败使用
|
||||
* 参数验证失败返回结果
|
||||
* @param message 提示信息
|
||||
*/
|
||||
public static <T> CommonResult<T> validateFailed(String message) {
|
||||
CommonResult<T> result = new CommonResult<T>();
|
||||
result.setCode(ResultCode.FAILED.getCode());
|
||||
result.setMessage(message);
|
||||
return result;
|
||||
return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户没有登录
|
||||
* 未登录返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> unauthorized() {
|
||||
return failed(ResultCode.UNAUTHORIZED);
|
||||
public static <T> CommonResult<T> unauthorized(T data) {
|
||||
return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户没有相应权限
|
||||
* 未授权返回结果
|
||||
*/
|
||||
public static <T> CommonResult<T> forbidden() {
|
||||
return failed(ResultCode.UNAUTHORIZED);
|
||||
public static <T> CommonResult<T> forbidden(T data) {
|
||||
return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
|
||||
}
|
||||
|
||||
public long getCode() {
|
||||
|
||||
@@ -7,5 +7,5 @@ package com.macro.mall.common.api;
|
||||
public interface IErrorCode {
|
||||
long getCode();
|
||||
|
||||
String getMsg();
|
||||
String getMessage();
|
||||
}
|
||||
|
||||
@@ -11,18 +11,18 @@ public enum ResultCode implements IErrorCode {
|
||||
UNAUTHORIZED(401, "暂未登录或token已经过期"),
|
||||
FORBIDDEN(403, "没有相关权限");
|
||||
private long code;
|
||||
private String msg;
|
||||
private String message;
|
||||
|
||||
private ResultCode(long code, String msg) {
|
||||
private ResultCode(long code, String message) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user