主题
国际化使用说明
WARNING
实现多语言的消息提示。
多语言请求header
:wueasy-language
,值为语言代码。
设置默认语言
yaml
wueasy:
i18n:
defaultLanguage: zh
创建多语言文件
WARNING
在工程中,创建i18n
文件夹,用于保存多语言文件配置,文件名按照规则框架messages_{语言代码}.properties
,
- 中文多语言文件
messages_zh.properties
properties
ERROR=很抱歉,系统繁忙,请稍后再试!
FILE_MAX_SIZE=文件大小超出限制!
SERVER_PARAM_ERROR=参数格式错误!
CAPTCHA_SEND_OFTEN=验证码发送频繁,请稍后再试!
CAPTCHA_SEND_LIMIT_IP=当前ip发送验证码超出限额,请明天再试!
CAPTCHA_SEND_LIMIT_CODE=当前号码发送消息超出限额,请明天再试!
CAPTCHA_EMPTY=验证码未发送或已过期,请重新发送!
CAPTCHA_MISMATCHING=验证码不匹配!
LOCK_ERROR=获取锁失败,请重试!
JSON_PARSE_ERROR=json转换失败!
CRYPT_RSA_EMPTY=秘钥内容为空!
CRYPT_RSA_ENCRYPT_ERROR=加密失败!
CRYPT_RSA_DECRYPT_ERROR=解密失败!
FILE_IO_ERROR=上传失败!
FILE_DOWN_ERROR=下载失败!
FILE_ERROR=上传失败!
FILE_NOT_EXIST_ERROR=文件不存在!
FILE_EMPTY=文件不能为空!
FILE_EXTNAME=禁止上传文件类型!
CRYPTO_ENCRYPT_ERROR=加密失败!
CRYPTO_DECRYPT_ERROR=解密失败!
DATE_PARSE_ERROR=日期转换异常!
MIN_PAGE_NUM_ERROR=页码最小值为1!
MAX_PAGE_SIZE_ERROR=每页数量最大值为1000!
MIN_PAGE_SIZE_ERROR=每页数量最小值为1!
- 英文多语言文件
messages_en.properties
properties
ERROR=Sorry, the system is busy. Please try again later!
FILE_MAX_SIZE=The file size exceeds the limit!
SERVER_PARAM_ERROR=Parameter format error!
CAPTCHA_SEND_OFTEN=he verification code is sent frequently, please try again later!
CAPTCHA_SEND_LIMIT_IP=当The verification code sent by the previous IP exceeded the limit. Please try again tomorrow!
CAPTCHA_SEND_LIMIT_CODE=The current number exceeds the limit for sending messages. Please try again tomorrow!
CAPTCHA_EMPTY=The verification code has not been sent or has expired. Please resend it!
CAPTCHA_MISMATCHING=The verification code does not match!
LOCK_ERROR=Failed to obtain lock, please try again!
JSON_PARSE_ERROR=JSON conversion failed!
CRYPT_RSA_EMPTY=The key content is empty!
CRYPT_RSA_ENCRYPT_ERROR=Encryption failed!
CRYPT_RSA_DECRYPT_ERROR=Decryption failed!
FILE_IO_ERROR=Upload failed!
FILE_DOWN_ERROR=Download failed!
FILE_ERROR=Upload failed!
FILE_NOT_EXIST_ERROR=The file does not exist!
FILE_EMPTY=The file cannot be empty!
FILE_EXTNAME=Prohibit uploading file types!
CRYPTO_ENCRYPT_ERROR=Encryption failed!
CRYPTO_DECRYPT_ERROR=Decryption failed!
DATE_PARSE_ERROR=Date conversion exception!
MIN_PAGE_NUM_ERROR=The minimum page number is 1!
MAX_PAGE_SIZE_ERROR=The maximum number of pages is 1000!
MIN_PAGE_SIZE_ERROR=The minimum number of pages is 1!
使用示例参考
参数格式验证
message
错误提示中指定为错误编码,然后把错误编码配置到多语言文件中
java
@Getter
@Setter
public class BasePageDto {
/**
* 第几页
*/
@Min(value = 1,message = "MIN_PAGE_NUM_ERROR")
private long pageNum = 1;
/**
* 每页数量
*/
@Max(value = 1000,message = "MAX_PAGE_SIZE_ERROR")
@Min(value = 1,message = "MIN_PAGE_SIZE_ERROR")
private int pageSize = 20;
}
业务代码处理
业务代码中抛出
InvokeException
异常,异常消息为错误编码,然后把错误编码配置到多语言文件中
java
if (!"admin".equals(dto.getAccountNo()) || !"123456".equals(dto.getPassword())) {
throw new InvokeException(-1, "USER_OR_PASSWORD_ERROR");
}