Update HttpHandler.java

cyj
pbvfus8to 8 months ago
parent e77de28600
commit bce5cbda95

@ -18,17 +18,37 @@ import java.io.PrintWriter;
import java.util.Objects;
/**
* HttpHandlerSpringWebServerResponseEntityYamiShopBindException
* JSONHTTP便
*
* @author
* @date 2022/3/28 14:15
*/
@Component
// 使用@Component注解将该类标记为Spring的组件使得Spring能够扫描并管理这个类将其纳入到Spring容器中方便进行依赖注入等操作。
public class HttpHandler {
// 创建一个名为logger的静态常量用于记录日志信息通过LoggerFactory获取HttpHandler类对应的Logger实例方便在类的各个方法中记录不同级别的日志
// 例如记录操作过程中的错误信息、调试信息等,有助于排查问题和了解程序的执行情况。
private static final Logger logger = LoggerFactory.getLogger(HttpHandler.class);
// 使用@Autowired注解进行依赖注入将Spring容器中管理的ObjectMapper实例注入到当前类中ObjectMapper主要用于将Java对象转换为JSON字符串序列化以及将JSON字符串转换为Java对象反序列化
// 在将ServerResponseEntity对象转换为JSON格式并写入HTTP响应时会用到它。
@Autowired
private ObjectMapper objectMapper;
/**
* ServerResponseEntityJSONWebHTTP
* ServerResponseEntity
* ServletRequestAttributesnull
* HttpServletResponsenull
* UTF-8JSONContentTypeAPPLICATION_JSON_VALUE
* ObjectMapperServerResponseEntityJSON使PrintWriterHTTPIOException
* YamiShopBindExceptionIOException便
*
* @param serverResponseEntity JSONHTTP
* @param <T> ServerResponseEntity
*/
public <T> void printServerResponseToWeb(ServerResponseEntity<T> serverResponseEntity) {
if (serverResponseEntity == null) {
logger.info("print obj is null");
@ -59,6 +79,16 @@ public class HttpHandler {
}
}
/**
* YamiShopBindExceptionWebHTTP
* YamiShopBindException
* ServerResponseEntityprintServerResponseToWebHTTP
* ServerResponseEntityServerResponseEntitygetCodegetMessage
* printServerResponseToWebHTTP使
*
* @param yamiShopBindException HTTP便
* @param <T> printServerResponseToWeb(ServerResponseEntity<T>)使
*/
public <T> void printServerResponseToWeb(YamiShopBindException yamiShopBindException) {
if (yamiShopBindException == null) {
logger.info("print obj is null");

Loading…
Cancel
Save