SpringBoot 接口异常统一处理

当接口出现未知异常时, 如何返回统一的信息? Response.java: package com.ncucoder.collector.vo; import lombok.Data; import lombok.NoArgsConstructor; /** * @author <a href="https://hsowan.me">hsowan</a> **/ @Data @NoArgsConstructor public class Response { private Integer code; private Object body; public Response(Integer code, Object body) { this.code = code; this.body = body; } } GlobalExceptionHandler.java: package com.ncucoder.collector.advice; import com.ncucoder.collector.vo.Response; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletResponse; /** * @author <a href="https://hsowan....

August 13, 2019 · 1 min · K8sCat

Servlet Lifecycle

{% img /images/servlet-lifecycle.png %}

July 26, 2019 · 1 min · K8sCat