本文主要是介绍JAVA 标准接口返回与i18n国际化配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
不喜欢废话直接上代码
标准通用返回
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.propertiesreturn ResourceBundle.getBundle("message", language);}return ResourceBundle.getBundle("message");}
}
配置文件如下图
简单弄个controller测试一下
看标准返回的格式
如果对您有用,感谢老爷点个赞,谢谢。
这篇关于JAVA 标准接口返回与i18n国际化配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!