@RestControllerを使用して、戻り値の統一処理 2218 ワード @ControllerAdvice public class RestControllerResponseAdvice implements ResponseBodyAdvice { @Override public boolean supports(MethodParameter returnType, Class extends HttpMessageConverter>> converterType) { return true; } @Override public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class extends HttpMessageConverter>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { // body if (body instanceof String) { String msg = (String) body; ResultJson resultJson = new ResultJson("-1", msg); // controller String , ResultJson , StringMessageConverter , return JSON.toJSONString(resultJson); } else if (body instanceof Object) { Object data = (Object) body; ResultJson resultJson = new ResultJson(data); return resultJson; } return body; } } /** * * : * * @author JiaJiCheng * @date 2018 8 24 */ public class ResultJson implements Serializable{ /** * */ private static final long serialVersionUID = 1L; // 0 private String code = "0"; // private String msg = ""; // private Object data = ""; public ResultJson() { } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getData() { return data; } public void setData(Object data) { this.data = data; } public ResultJson(String code) { this.code = code; } public ResultJson(String code, String msg) { this.code = code; this.msg = msg; } public ResultJson(Object data) { this.data = data; } public ResultJson(String code, String msg, Object data) { this.code = code; this.msg = msg; this.data = data; } } [JS] Date クラスクラスクラスのプロパティ