常常在需求中遇到国际化的要求,而国际化最常见的就是中英文切换,除了前端,后端也需要进行国际化处理,这里来记录一下我实现国际化的步骤代码。
1、在resource下的i18n下建立messages.properties、messages_en.properties、messages_zh.properties
分别配置测试变量,下面是我的配置
messages.properties
#Default Tips
#Base General Message
base.response.success.msg=成功
base.response.fail.msg=失败
messages_en.properties
#English Tips
#Base General Message
base.response.success.msg=success
base.response.fail.msg=fail
messages_zh.properties
#Chinese Tips
#Base General Message
base.response.success.msg=成功
base.response.fail.msg=失败
2、国家化配置
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Con