feat: 使用 jdk instanceof 新特性

This commit is contained in:
xingyu4j
2025-08-28 15:10:52 +08:00
parent 495ef72a39
commit 224980aa1a
7 changed files with 12 additions and 20 deletions

View File

@@ -184,8 +184,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpMessageNotReadableException.class)
public CommonResult<?> methodArgumentTypeInvalidFormatExceptionHandler(HttpMessageNotReadableException ex) {
log.warn("[methodArgumentTypeInvalidFormatExceptionHandler]", ex);
if (ex.getCause() instanceof InvalidFormatException) {
InvalidFormatException invalidFormatException = (InvalidFormatException) ex.getCause();
if (ex.getCause() instanceof InvalidFormatException invalidFormatException) {
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数类型错误:%s", invalidFormatException.getValue()));
}
if (StrUtil.startWith(ex.getMessage(), "Required request body is missing")) {

View File

@@ -146,10 +146,9 @@ public class WebFrameworkUtils {
public static HttpServletRequest getRequest() {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (!(requestAttributes instanceof ServletRequestAttributes)) {
if (!(requestAttributes instanceof ServletRequestAttributes servletRequestAttributes)) {
return null;
}
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
return servletRequestAttributes.getRequest();
}