org.shoulder.web.advice.RestControllerUnionResponseAdvice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shoulder-web Show documentation
Show all versions of shoulder-web Show documentation
shoulder WEB 模块,基于Spring Boot Web提供了 Controller AOP 日志、AOP异常处理,统一返回值,健康检查,租户、用户解析,Web
安全防护,通用CrudController,动态字典,标签管理,HTTP client AOP日志、AOP异常处理等能力,助力Web飞速开发。
The newest version!
package org.shoulder.web.advice;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import org.apache.commons.collections4.CollectionUtils;
import org.shoulder.core.dto.response.BaseResult;
import org.shoulder.core.dto.response.ListResult;
import org.shoulder.core.log.Logger;
import org.shoulder.core.log.ShoulderLoggers;
import org.shoulder.core.util.ArrayUtils;
import org.shoulder.core.util.ServletUtil;
import org.shoulder.core.util.StringUtils;
import org.shoulder.web.annotation.SkipResponseWrap;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
/**
* 统一接口返回值
* 自动将 json 或者 str 类型返回值(RestController 的返回值)用 {@link BaseResult} 包装。
* 关闭包装:
* 禁止对某个方法返回值包装: 方法上添加 {@link SkipResponseWrap}
* 禁止对某个RestController类的所有返回值包装: 类上添加 {@link SkipResponseWrap}
* 禁用功能: shoulder.web.restResponse=false
*
* 如果希望使用自己项目中的返回值类,返回值继承 {@link BaseResult} 类即可。
*
*
* @author lym
*/
@RestControllerAdvice
public class RestControllerUnionResponseAdvice implements ResponseBodyAdvice
© 2015 - 2025 Weber Informatics LLC | Privacy Policy