抬头做人,低头做事。
项目中用到spring,分配了个发送邮件功能。
拿下来看业务很简单。
邮件的内容是变量和固定字符拼接起来的。
用MessageFormat的时候感觉很强大嘛,只要如下做就可以了。
int fileCount = 1273; String diskName = "MyDisk"
Object[] testArgs = {new Long(fileCount), diskName};
MessageFormat form = new MessageFormat( "The disk \"{1}\" contains {0} file(s)."); System.out.println(form.format(testArgs));
有如:
String format = "i am {0}, i am from {1}"//在实际的项目中我们使用了配置文件的方式将类似于格式的format注入到要使用的类中,十分方便 String text = MessageFormat(format, new Object[]{"dc", "china"})