- 后端:替换 swagger bootstrap ui ,一下子接口文档好看了。
- 后端:增加 swagger AutoConfiguration 配置类 - 后端:统一访问日志的记录
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package cn.iocoder.common.framework.constant;
|
||||
|
||||
/**
|
||||
* Mall 全局枚举
|
||||
*/
|
||||
public interface MallConstants {
|
||||
|
||||
// 全局请求路径枚举类,用于定义不同用户类型的根请求路径
|
||||
/**
|
||||
* 根路径 - 用户
|
||||
*/
|
||||
String ROOT_PATH_USER = "/users";
|
||||
/**
|
||||
* 根路径 - 管理员
|
||||
*/
|
||||
String ROOT_PATH_ADMIN = "/admins";
|
||||
|
||||
// 用户类型
|
||||
/**
|
||||
* 用户类型 - 用户
|
||||
*/
|
||||
Integer USER_TYPE_USER = 1;
|
||||
/**
|
||||
* 用户类型 - 管理员
|
||||
*/
|
||||
Integer USER_TYPE_ADMIN = 2;
|
||||
|
||||
// HTTP Request Attr
|
||||
/**
|
||||
* HTTP Request Attr - 用户编号
|
||||
*/
|
||||
String REQUEST_ATTR_USER_ID_KEY = "mall_user_id";
|
||||
/**
|
||||
* HTTP Request Attr - 用户类型
|
||||
*/
|
||||
String REQUEST_ATTR_USER_TYPE_KEY = "mall_user_type";
|
||||
/**
|
||||
* HTTP Request Attr - Controller 执行返回
|
||||
*/
|
||||
String REQUEST_ATTR_COMMON_RESULT = "mall_common_result";
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.iocoder.common.framework.config;
|
||||
package cn.iocoder.common.framework.exception;
|
||||
|
||||
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
|
||||
import cn.iocoder.common.framework.exception.ServiceException;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -5,6 +5,11 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Cors 过滤器
|
||||
*
|
||||
* 未来使用 {@link org.springframework.web.filter.CorsFilter} 替换
|
||||
*/
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
@Override
|
||||
@@ -32,4 +37,4 @@ public class CorsFilter implements Filter {
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class HttpUtil {
|
||||
*/
|
||||
public static final String DEFAULT_CHARACTER_ENCODING = "ISO-8859-1";
|
||||
|
||||
public static String obtainAccess(HttpServletRequest request) {
|
||||
public static String obtainAuthorization(HttpServletRequest request) {
|
||||
String authorization = request.getHeader("Authorization");
|
||||
if (!StringUtils.hasText(authorization)) {
|
||||
return null;
|
||||
@@ -316,4 +316,4 @@ public class HttpUtil {
|
||||
return enc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package cn.iocoder.common.framework.util;
|
||||
|
||||
import cn.iocoder.common.framework.constant.MallConstants;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MallUtil {
|
||||
|
||||
public static Integer getUserId(ServletRequest request) {
|
||||
return (Integer) request.getAttribute(MallConstants.REQUEST_ATTR_USER_ID_KEY);
|
||||
}
|
||||
|
||||
public static void setUserId(ServletRequest request, Integer userId) {
|
||||
request.setAttribute(MallConstants.REQUEST_ATTR_USER_ID_KEY, userId);
|
||||
}
|
||||
|
||||
public static Integer getUserType(ServletRequest request) {
|
||||
return (Integer) request.getAttribute(MallConstants.REQUEST_ATTR_USER_TYPE_KEY);
|
||||
}
|
||||
|
||||
public static void setUserType(ServletRequest request, Integer userType) {
|
||||
request.setAttribute(MallConstants.REQUEST_ATTR_USER_TYPE_KEY, userType);
|
||||
}
|
||||
|
||||
public static CommonResult getCommonResult(ServletRequest request) {
|
||||
return (CommonResult) request.getAttribute(MallConstants.REQUEST_ATTR_COMMON_RESULT);
|
||||
}
|
||||
|
||||
public static void setCommonResult(ServletRequest request, CommonResult result) {
|
||||
request.setAttribute(MallConstants.REQUEST_ATTR_COMMON_RESULT, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得链路追踪编号
|
||||
*
|
||||
* 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。
|
||||
*
|
||||
* 默认情况下,我们使用 Apache SkyWalking 的 traceId 作为链路追踪编号。当然,可能会存在并未引入 Skywalking 的情况,此时使用 UUID 。
|
||||
*
|
||||
* @return 链路追踪编号
|
||||
*/
|
||||
public static String getTraceId() {
|
||||
String traceId = TraceContext.traceId();
|
||||
if (StringUtil.hasText(traceId)) {
|
||||
return traceId;
|
||||
}
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CommonResult<T> implements Serializable {
|
||||
public final class CommonResult<T> implements Serializable {
|
||||
|
||||
public static Integer CODE_SUCCESS = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user