springboot返回值國際化處理
阿新 • • 發佈:2018-12-19
一:啟動類內配置
二:國際化檔案
三,攔截器
|
返回包裝類為:
package com.otcbi.common.dto; import java.util.HashMap; import java.util.Map; public class OperateResult<T> { private String innerException; public String getInnerException() { return innerException; } public static Map<String, Object> renderPage(Page page, Object object) { Map<String, Object> reqMap = new HashMap<String, Object>(); reqMap.put("page", page); reqMap.put("objects", object); return reqMap; } public Boolean success() { boolean flag = true; if (this.getData() == null && !this.getStatus().equalsIgnoreCase("200")) { flag = false; } return flag; } public OperateResult(T data) { this.status = "200"; this.innerException = ""; this.message = ""; this.data = data; } public void setInnerException(String innerException) { this.innerException = innerException; } public OperateResult(String innerException, String message, T data) { super(); this.innerException = innerException; this.message = message; this.data = data; this.status = "400"; } public OperateResult(String innerException, String message, T data, String status) { super(); this.innerException = innerException; this.message = message; this.data = data; this.status = status; } public OperateResult() { super(); } private String status; private String message; public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } private T data; public T getData() { return data; } public void setData(T data) { this.data = data; } public static OperateResult getVersionErrorOp() { OperateResult opForVersion = new OperateResult(); opForVersion.setData(null); opForVersion.setMessage("不支援請求的版本!"); return opForVersion; } public static OperateResult getParametersNotCompleteErrorOp(String descript) { OperateResult opForVersion = new OperateResult(); opForVersion.setData(null); opForVersion.setMessage(descript); return opForVersion; } } |