国际化设计
1.书写多语言的properties文件
validation.properties
validation_en.properties
validation_ja.properties
结构如下
2.书写配置文件
在 application.yml文件中加入配置
编写 ValidationConfiguration.java文件
3.使用方式
注意:如果默认没有设置语言则为系统默认语言为标准
4.重启服务,测试
在header添加Accept-Language参数,测试英文。达到预想结果
测试不存在的语言
在此多语言参数验证就已实现完成,细心的网友会看见 请求参数不正确并没有随着多语言的编号而变化
设计业务提示国际化
设计业务提示多语言,可以参照上面的参数验证做出设计。但是难点在于如何让业务枚举或者异常枚举按照语言不同,选择不同的properties文件做出处理。按照这个思想,可以在枚举中定义一个code,通过这个code和前端传的语言来确定properties文件
1.编写properties文件
result_zh.properties
result_en.properties
result_ja.properties
结构如下
2.枚举设计
定义一个接口,使枚举类都实现这个接口
3.编写核心文件ResultResource.java
枚举类做出以下调整