refactor: 优化部分代码

修复 Sonar 扫描问题
This commit is contained in:
2024-01-27 14:33:15 +08:00
parent 9c0cd2fd9d
commit fe0bff3d3e
13 changed files with 56 additions and 44 deletions

View File

@@ -37,6 +37,9 @@ import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoC
@Slf4j @Slf4j
abstract class SaTokenDaoConfiguration { abstract class SaTokenDaoConfiguration {
private SaTokenDaoConfiguration() {
}
/** /**
* 自定义持久层实现类-Redis * 自定义持久层实现类-Redis
*/ */

View File

@@ -40,7 +40,7 @@ public class GlobalSaTokenExceptionHandler {
* 认证异常-登录认证 * 认证异常-登录认证
*/ */
@ExceptionHandler(NotLoginException.class) @ExceptionHandler(NotLoginException.class)
public R handleNotLoginException(NotLoginException e, HttpServletRequest request) { public R<Void> handleNotLoginException(NotLoginException e, HttpServletRequest request) {
log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e); log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e);
String errorMsg = switch (e.getType()) { String errorMsg = switch (e.getType()) {
case NotLoginException.KICK_OUT -> "您已被踢下线。"; case NotLoginException.KICK_OUT -> "您已被踢下线。";
@@ -54,7 +54,7 @@ public class GlobalSaTokenExceptionHandler {
* 认证异常-权限认证 * 认证异常-权限认证
*/ */
@ExceptionHandler(NotPermissionException.class) @ExceptionHandler(NotPermissionException.class)
public R handleNotPermissionException(NotPermissionException e, HttpServletRequest request) { public R<Void> handleNotPermissionException(NotPermissionException e, HttpServletRequest request) {
log.error("请求地址 [{}],权限码校验失败。", request.getRequestURI(), e); log.error("请求地址 [{}],权限码校验失败。", request.getRequestURI(), e);
return R.fail(HttpStatus.FORBIDDEN.value(), "没有访问权限,请联系管理员授权"); return R.fail(HttpStatus.FORBIDDEN.value(), "没有访问权限,请联系管理员授权");
} }
@@ -63,7 +63,7 @@ public class GlobalSaTokenExceptionHandler {
* 认证异常-角色认证 * 认证异常-角色认证
*/ */
@ExceptionHandler(NotRoleException.class) @ExceptionHandler(NotRoleException.class)
public R handleNotRoleException(NotRoleException e, HttpServletRequest request) { public R<Void> handleNotRoleException(NotRoleException e, HttpServletRequest request) {
log.error("请求地址 [{}],角色权限校验失败。", request.getRequestURI(), e); log.error("请求地址 [{}],角色权限校验失败。", request.getRequestURI(), e);
return R.fail(HttpStatus.FORBIDDEN.value(), "没有访问权限,请联系管理员授权"); return R.fail(HttpStatus.FORBIDDEN.value(), "没有访问权限,请联系管理员授权");
} }

View File

@@ -24,7 +24,6 @@ import top.charles7c.continew.starter.core.constant.StringConstants;
import java.time.Duration; import java.time.Duration;
import java.util.Collection; import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@@ -138,7 +137,7 @@ public class RedisUtils {
*/ */
public static Collection<String> keys(final String keyPattern) { public static Collection<String> keys(final String keyPattern) {
Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(getNameMapper().map(keyPattern)); Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(getNameMapper().map(keyPattern));
return stream.map(key -> getNameMapper().unmap(key)).collect(Collectors.toList()); return stream.map(key -> getNameMapper().unmap(key)).toList();
} }
/** /**

View File

@@ -42,6 +42,9 @@ import top.charles7c.continew.starter.core.constant.PropertiesConstants;
@Slf4j @Slf4j
abstract class BehaviorCaptchaCacheConfiguration { abstract class BehaviorCaptchaCacheConfiguration {
private BehaviorCaptchaCacheConfiguration() {
}
/** /**
* 自定义缓存实现类-Redis * 自定义缓存实现类-Redis
*/ */
@@ -49,7 +52,8 @@ abstract class BehaviorCaptchaCacheConfiguration {
@AutoConfigureBefore(RedissonAutoConfiguration.class) @AutoConfigureBefore(RedissonAutoConfiguration.class)
@ConditionalOnProperty(name = PropertiesConstants.CAPTCHA_BEHAVIOR + ".cache-type", havingValue = "redis") @ConditionalOnProperty(name = PropertiesConstants.CAPTCHA_BEHAVIOR + ".cache-type", havingValue = "redis")
static class Redis { static class Redis {
static { @PostConstruct
public void postConstruct() {
CaptchaServiceFactory.cacheService.put(StorageType.REDIS.name() CaptchaServiceFactory.cacheService.put(StorageType.REDIS.name()
.toLowerCase(), new BehaviorCaptchaCacheServiceImpl()); .toLowerCase(), new BehaviorCaptchaCacheServiceImpl());
log.debug("[ContiNew Starter] - Auto Configuration 'Behavior-CaptchaCache-Redis' completed initialization."); log.debug("[ContiNew Starter] - Auto Configuration 'Behavior-CaptchaCache-Redis' completed initialization.");
@@ -61,7 +65,6 @@ abstract class BehaviorCaptchaCacheConfiguration {
*/ */
@ConditionalOnProperty(name = PropertiesConstants.CAPTCHA_BEHAVIOR + ".cache-type", havingValue = "custom") @ConditionalOnProperty(name = PropertiesConstants.CAPTCHA_BEHAVIOR + ".cache-type", havingValue = "custom")
static class Custom { static class Custom {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public CaptchaCacheService captchaCacheService(BehaviorCaptchaProperties properties) { public CaptchaCacheService captchaCacheService(BehaviorCaptchaProperties properties) {

View File

@@ -29,6 +29,9 @@ import java.lang.reflect.Type;
*/ */
public class ClassUtils { public class ClassUtils {
private ClassUtils() {
}
/** /**
* 获得给定类的所有泛型参数 * 获得给定类的所有泛型参数
* *

View File

@@ -22,7 +22,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 反射工具类 * 反射工具类
@@ -45,7 +44,7 @@ public class ReflectUtils {
*/ */
public static List<String> getNonStaticFieldsName(Class<?> beanClass) throws SecurityException { public static List<String> getNonStaticFieldsName(Class<?> beanClass) throws SecurityException {
List<Field> nonStaticFields = getNonStaticFields(beanClass); List<Field> nonStaticFields = getNonStaticFields(beanClass);
return nonStaticFields.stream().map(Field::getName).collect(Collectors.toList()); return nonStaticFields.stream().map(Field::getName).toList();
} }
/** /**
@@ -58,6 +57,6 @@ public class ReflectUtils {
*/ */
public static List<Field> getNonStaticFields(Class<?> beanClass) throws SecurityException { public static List<Field> getNonStaticFields(Class<?> beanClass) throws SecurityException {
Field[] fields = ReflectUtil.getFields(beanClass); Field[] fields = ReflectUtil.getFields(beanClass);
return Arrays.stream(fields).filter(f -> !Modifier.isStatic(f.getModifiers())).collect(Collectors.toList()); return Arrays.stream(fields).filter(f -> !Modifier.isStatic(f.getModifiers())).toList();
} }
} }

View File

@@ -98,9 +98,8 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
return where; return where;
} }
if (DataScope.DEPT_AND_CHILD.equals(dataScope)) { if (DataScope.DEPT_AND_CHILD.equals(dataScope)) {
// select t1.* from table as t1 where t1.`dept_id` in (select `id` from `sys_dept` where `id` = xxx or
// find_in_set(xxx, `ancestors`));
// 构建子查询 // 构建子查询
// 语句示例select t1.* from table as t1 where t1.`dept_id` in (select `id` from `sys_dept` where `id` = xxx or find_in_set(xxx, `ancestors`));
SubSelect subSelect = new SubSelect(); SubSelect subSelect = new SubSelect();
PlainSelect select = new PlainSelect(); PlainSelect select = new PlainSelect();
select.setSelectItems(Collections.singletonList(new SelectExpressionItem(new Column(id)))); select.setSelectItems(Collections.singletonList(new SelectExpressionItem(new Column(id))));
@@ -120,21 +119,21 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
inExpression.setRightExpression(subSelect); inExpression.setRightExpression(subSelect);
expression = null != expression ? new OrExpression(expression, inExpression) : inExpression; expression = null != expression ? new OrExpression(expression, inExpression) : inExpression;
} else if (DataScope.DEPT.equals(dataScope)) { } else if (DataScope.DEPT.equals(dataScope)) {
// select t1.* from table as t1 where t1.`dept_id` = xxx; // 语句示例:select t1.* from table as t1 where t1.`dept_id` = xxx;
EqualsTo equalsTo = new EqualsTo(); EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(this.buildColumn(tableAlias, deptId)); equalsTo.setLeftExpression(this.buildColumn(tableAlias, deptId));
equalsTo.setRightExpression(new LongValue(currentUser.getDeptId())); equalsTo.setRightExpression(new LongValue(currentUser.getDeptId()));
expression = null != expression ? new OrExpression(expression, equalsTo) : equalsTo; expression = null != expression ? new OrExpression(expression, equalsTo) : equalsTo;
} else if (DataScope.SELF.equals(dataScope)) { } else if (DataScope.SELF.equals(dataScope)) {
// select t1.* from table as t1 where t1.`create_user` = xxx; // 语句示例:select t1.* from table as t1 where t1.`create_user` = xxx;
EqualsTo equalsTo = new EqualsTo(); EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(this.buildColumn(tableAlias, dataPermission.userId())); equalsTo.setLeftExpression(this.buildColumn(tableAlias, dataPermission.userId()));
equalsTo.setRightExpression(new LongValue(currentUser.getUserId())); equalsTo.setRightExpression(new LongValue(currentUser.getUserId()));
expression = null != expression ? new OrExpression(expression, equalsTo) : equalsTo; expression = null != expression ? new OrExpression(expression, equalsTo) : equalsTo;
} else if (DataScope.CUSTOM.equals(dataScope)) { } else if (DataScope.CUSTOM.equals(dataScope)) {
// select t1.* from table as t1 where t1.`dept_id` in (select `dept_id` from `sys_role_dept` where
// `role_id` = xxx);
// 构建子查询 // 构建子查询
// 语句示例select t1.* from table as t1 where t1.`dept_id` in (select `dept_id` from `sys_role_dept` where
// `role_id` = xxx);
SubSelect subSelect = new SubSelect(); SubSelect subSelect = new SubSelect();
PlainSelect select = new PlainSelect(); PlainSelect select = new PlainSelect();
select.setSelectItems(Collections.singletonList(new SelectExpressionItem(new Column(deptId)))); select.setSelectItems(Collections.singletonList(new SelectExpressionItem(new Column(deptId))));

View File

@@ -153,7 +153,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
@Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH) @Parameter(name = "ids", description = "ID 列表", example = "1,2", in = ParameterIn.PATH)
@ResponseBody @ResponseBody
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public R delete(@PathVariable List<Long> ids) { public R<Void> delete(@PathVariable List<Long> ids) {
this.checkPermission(Api.DELETE); this.checkPermission(Api.DELETE);
baseService.delete(ids); baseService.delete(ids);
return R.ok("删除成功"); return R.ok("删除成功");

View File

@@ -24,6 +24,9 @@ package top.charles7c.continew.starter.extension.crud.constant;
*/ */
public class ContainerPool { public class ContainerPool {
private ContainerPool() {
}
/** /**
* 用户昵称 * 用户昵称
*/ */

View File

@@ -63,9 +63,9 @@ public class CrudRequestMappingHandlerMapping extends RequestMappingHandlerMappi
private RequestMappingInfo getMappingForMethodWrapper(@NonNull Method method, private RequestMappingInfo getMappingForMethodWrapper(@NonNull Method method,
@NonNull Class<?> handlerType, @NonNull Class<?> handlerType,
CrudRequestMapping crudRequestMapping) { CrudRequestMapping crudRequestMapping) {
RequestMappingInfo info = this.createRequestMappingInfo(method); RequestMappingInfo info = this.buildRequestMappingInfo(method);
if (null != info) { if (null != info) {
RequestMappingInfo typeInfo = this.createRequestMappingInfo(handlerType); RequestMappingInfo typeInfo = this.buildRequestMappingInfo(handlerType);
if (null != typeInfo) { if (null != typeInfo) {
info = typeInfo.combine(info); info = typeInfo.combine(info);
} }
@@ -79,11 +79,11 @@ public class CrudRequestMappingHandlerMapping extends RequestMappingHandlerMappi
return info; return info;
} }
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { private RequestMappingInfo buildRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class); RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class<?> clazz RequestCondition<?> condition = (element instanceof Class<?> clazz
? getCustomTypeCondition(clazz) ? getCustomTypeCondition(clazz)
: getCustomMethodCondition((Method)element)); : getCustomMethodCondition((Method)element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null); return (requestMapping != null ? super.createRequestMappingInfo(requestMapping, condition) : null);
} }
} }

View File

@@ -68,9 +68,6 @@ public class PageQuery extends SortQuery {
@Range(min = 1, max = 1000, message = "每页条数(取值范围 {min}-{max}") @Range(min = 1, max = 1000, message = "每页条数(取值范围 {min}-{max}")
private Integer size = DEFAULT_SIZE; private Integer size = DEFAULT_SIZE;
public PageQuery() {
}
/** /**
* 基于分页查询条件转换为 MyBatis Plus 分页条件 * 基于分页查询条件转换为 MyBatis Plus 分页条件
* *

View File

@@ -57,12 +57,12 @@ public final class RecordableServletHttpRequest implements RecordableHttpRequest
return URI.create(request.getRequestURL().toString()); return URI.create(request.getRequestURL().toString());
} }
try { try {
StringBuffer urlBuffer = this.appendQueryString(queryString); StringBuilder urlBuilder = this.appendQueryString(queryString);
return new URI(urlBuffer.toString()); return new URI(urlBuilder.toString());
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
String encoded = UriUtils.encodeQuery(queryString, StandardCharsets.UTF_8); String encoded = UriUtils.encodeQuery(queryString, StandardCharsets.UTF_8);
StringBuffer urlBuffer = this.appendQueryString(encoded); StringBuilder urlBuilder = this.appendQueryString(encoded);
return URI.create(urlBuffer.toString()); return URI.create(urlBuilder.toString());
} }
} }
@@ -94,7 +94,9 @@ public final class RecordableServletHttpRequest implements RecordableHttpRequest
: Collections.unmodifiableMap(request.getParameterMap()); : Collections.unmodifiableMap(request.getParameterMap());
} }
private StringBuffer appendQueryString(String queryString) { private StringBuilder appendQueryString(String queryString) {
return request.getRequestURL().append(StringConstants.QUESTION_MARK).append(queryString); return new StringBuilder().append(request.getRequestURL())
.append(StringConstants.QUESTION_MARK)
.append(queryString);
} }
} }

View File

@@ -47,11 +47,13 @@ import top.charles7c.continew.starter.web.model.R;
@RestControllerAdvice @RestControllerAdvice
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private static final String PARAM_FAILED = "请求地址 [{}],参数验证失败。";
/** /**
* 拦截自定义验证异常-错误请求 * 拦截自定义验证异常-错误请求
*/ */
@ExceptionHandler(BadRequestException.class) @ExceptionHandler(BadRequestException.class)
public R handleBadRequestException(BadRequestException e, HttpServletRequest request) { public R<Void> handleBadRequestException(BadRequestException e, HttpServletRequest request) {
log.warn("请求地址 [{}],自定义验证失败。", request.getRequestURI(), e); log.warn("请求地址 [{}],自定义验证失败。", request.getRequestURI(), e);
return R.fail(HttpStatus.BAD_REQUEST.value(), e.getMessage()); return R.fail(HttpStatus.BAD_REQUEST.value(), e.getMessage());
} }
@@ -60,8 +62,8 @@ public class GlobalExceptionHandler {
* 拦截校验异常-违反约束异常 * 拦截校验异常-违反约束异常
*/ */
@ExceptionHandler(ConstraintViolationException.class) @ExceptionHandler(ConstraintViolationException.class)
public R constraintViolationException(ConstraintViolationException e, HttpServletRequest request) { public R<Void> constraintViolationException(ConstraintViolationException e, HttpServletRequest request) {
log.warn("请求地址 [{}],参数验证失败。", request.getRequestURI(), e); log.warn(PARAM_FAILED, request.getRequestURI(), e);
String errorMsg = CollUtil.join(e String errorMsg = CollUtil.join(e
.getConstraintViolations(), StringConstants.CHINESE_COMMA, ConstraintViolation::getMessage); .getConstraintViolations(), StringConstants.CHINESE_COMMA, ConstraintViolation::getMessage);
return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg);
@@ -71,8 +73,8 @@ public class GlobalExceptionHandler {
* 拦截校验异常-绑定异常 * 拦截校验异常-绑定异常
*/ */
@ExceptionHandler(BindException.class) @ExceptionHandler(BindException.class)
public R handleBindException(BindException e, HttpServletRequest request) { public R<Void> handleBindException(BindException e, HttpServletRequest request) {
log.warn("请求地址 [{}],参数验证失败。", request.getRequestURI(), e); log.warn(PARAM_FAILED, request.getRequestURI(), e);
String errorMsg = CollUtil.join(e String errorMsg = CollUtil.join(e
.getAllErrors(), StringConstants.CHINESE_COMMA, DefaultMessageSourceResolvable::getDefaultMessage); .getAllErrors(), StringConstants.CHINESE_COMMA, DefaultMessageSourceResolvable::getDefaultMessage);
return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg);
@@ -82,8 +84,9 @@ public class GlobalExceptionHandler {
* 拦截校验异常-方法参数无效异常 * 拦截校验异常-方法参数无效异常
*/ */
@ExceptionHandler(MethodArgumentNotValidException.class) @ExceptionHandler(MethodArgumentNotValidException.class)
public R handleMethodArgumentNotValidException(MethodArgumentNotValidException e, HttpServletRequest request) { public R<Void> handleMethodArgumentNotValidException(MethodArgumentNotValidException e,
log.warn("请求地址 [{}],参数验证失败。", request.getRequestURI(), e); HttpServletRequest request) {
log.warn(PARAM_FAILED, request.getRequestURI(), e);
String errorMsg = CollUtil.join(e String errorMsg = CollUtil.join(e
.getAllErrors(), StringConstants.CHINESE_COMMA, DefaultMessageSourceResolvable::getDefaultMessage); .getAllErrors(), StringConstants.CHINESE_COMMA, DefaultMessageSourceResolvable::getDefaultMessage);
return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg);
@@ -93,8 +96,8 @@ public class GlobalExceptionHandler {
* 拦截校验异常-方法参数类型不匹配异常 * 拦截校验异常-方法参数类型不匹配异常
*/ */
@ExceptionHandler(MethodArgumentTypeMismatchException.class) @ExceptionHandler(MethodArgumentTypeMismatchException.class)
public R handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, public R<Void> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e,
HttpServletRequest request) { HttpServletRequest request) {
String errorMsg = StrUtil.format("参数名:[{}],期望参数类型:[{}]", e.getName(), e.getParameter().getParameterType()); String errorMsg = StrUtil.format("参数名:[{}],期望参数类型:[{}]", e.getName(), e.getParameter().getParameterType());
log.warn("请求地址 [{}],参数转换失败,{}。", request.getRequestURI(), errorMsg, e); log.warn("请求地址 [{}],参数转换失败,{}。", request.getRequestURI(), errorMsg, e);
return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg); return R.fail(HttpStatus.BAD_REQUEST.value(), errorMsg);
@@ -104,7 +107,7 @@ public class GlobalExceptionHandler {
* 拦截文件上传异常-超过上传大小限制 * 拦截文件上传异常-超过上传大小限制
*/ */
@ExceptionHandler(MaxUploadSizeExceededException.class) @ExceptionHandler(MaxUploadSizeExceededException.class)
public R handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) { public R<Void> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e, HttpServletRequest request) {
log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e); log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e);
String sizeLimit = StrUtil.subBetween(e.getMessage(), "The maximum size ", " for"); String sizeLimit = StrUtil.subBetween(e.getMessage(), "The maximum size ", " for");
String errorMsg = String.format("请上传小于 %sMB 的文件", NumberUtil.parseLong(sizeLimit) / 1024 / 1024); String errorMsg = String.format("请上传小于 %sMB 的文件", NumberUtil.parseLong(sizeLimit) / 1024 / 1024);
@@ -115,7 +118,8 @@ public class GlobalExceptionHandler {
* 拦截校验异常-请求方式不支持异常 * 拦截校验异常-请求方式不支持异常
*/ */
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public R handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request) { public R<Void> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
HttpServletRequest request) {
log.error("请求地址 [{}],不支持 [{}] 请求。", request.getRequestURI(), e.getMethod()); log.error("请求地址 [{}],不支持 [{}] 请求。", request.getRequestURI(), e.getMethod());
return R.fail(HttpStatus.METHOD_NOT_ALLOWED.value(), e.getMessage()); return R.fail(HttpStatus.METHOD_NOT_ALLOWED.value(), e.getMessage());
} }
@@ -124,7 +128,7 @@ public class GlobalExceptionHandler {
* 拦截业务异常 * 拦截业务异常
*/ */
@ExceptionHandler(BusinessException.class) @ExceptionHandler(BusinessException.class)
public R handleServiceException(BusinessException e, HttpServletRequest request) { public R<Void> handleServiceException(BusinessException e, HttpServletRequest request) {
log.error("请求地址 [{}],发生业务异常。", request.getRequestURI(), e); log.error("请求地址 [{}],发生业务异常。", request.getRequestURI(), e);
return R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return R.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
} }
@@ -133,7 +137,7 @@ public class GlobalExceptionHandler {
* 拦截未知的运行时异常 * 拦截未知的运行时异常
*/ */
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public R handleRuntimeException(RuntimeException e, HttpServletRequest request) { public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request) {
log.error("请求地址 [{}],发生系统异常。", request.getRequestURI(), e); log.error("请求地址 [{}],发生系统异常。", request.getRequestURI(), e);
return R.fail(e.getMessage()); return R.fail(e.getMessage());
} }
@@ -142,7 +146,7 @@ public class GlobalExceptionHandler {
* 拦截未知的系统异常 * 拦截未知的系统异常
*/ */
@ExceptionHandler(Throwable.class) @ExceptionHandler(Throwable.class)
public R handleException(Throwable e, HttpServletRequest request) { public R<Void> handleException(Throwable e, HttpServletRequest request) {
log.error("请求地址 [{}],发生未知异常。", request.getRequestURI(), e); log.error("请求地址 [{}],发生未知异常。", request.getRequestURI(), e);
return R.fail(e.getMessage()); return R.fail(e.getMessage());
} }