不喜欢废话直接上代码
标准通用返回
package com.luojie.common;
import com.luojie.common.inter.ResponseCommon;
import lombok.Data;
@Data
public class ResponseCommonImpl implements ResponseCommon {
int code;
String msg;
Object entity;
}
package com.luojie.common;
import org.springframework.http.HttpStatus;
public class ResponseUtil {
public static ResponseCommonImpl success(String msg, Object data) {
ResponseCommonImpl common = new ResponseCommonImpl();
common.setCode(HttpStatus.OK.value());
common.setMsg(msg);
common.setEntity(data);
return common;
}
public static ResponseCommonImpl failCommon(String msg, Object data) {
ResponseCommonImpl common = new ResponseCommonImpl();
common.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
common.setMsg(msg);
common.setEntity(data);
return common;
}
}
国际化配置
package com.luojie.util;
import java.util.Locale;
import java.util.ResourceBundle;
public class ResourceBundleUtil {
public static ResourceBundle getInstance(Locale language) {
if (language != null) {
// 这里的message是指文件的前缀(baseName)
// 国际化的命名规则是baseName_local.properties
return ResourceBundle.getBundle("message", language);
}
return ResourceBundle.getBundle("message");
}
}
配置文件如下图
简单弄个controller测试一下
看标准返回的格式
如果对您有用,感谢老爷点个赞,谢谢。