(2) Object[] rawOutput1 = new Object[] { "The city of customer ", name,"'s first address is ", city, "." }; System.out.println(StringUtils.join(rawOutput1));
显示结果:The city of customer John Smith's first address is Los Angeles.
解释:将数组元素连接起来。
2) org.apache.commons.configuration 配置包
Configuration parameters may be loaded from the following sources: 处理的配置文件类型:
Properties files
XML documents
Windows INI files
Property list files (plist)
JNDI
JDBC Datasource
System properties
Applet parameters
Servlet parameters
Different configuration sources can be mixed using a ConfigurationFactory and a CompositeConfiguration. Additional sources of configuration parameters can be created by using custom configuration objects. This customization can be achieved by extending AbstractConfiguration or AbstractFileConfiguration.
The full Javadoc API documentation is available here.
3)org.apache.commons.beanutils.BeanUtils配置包
关键方法的解释和运用:
(1) public static void copyProperties(Object dest, Object orig):
Copy property values from the origin bean to the destination bean for all cases where the property names are the same.
eg:BeanUtils.copyProperties(user1,user2);
(2) public static void copyProperty(Object bean, String name, Object value):
Copy the specified property value to the specified destination bean, performing any type conversion that is required.
eg:BeanUtils.copyProperty(student,"stuName","leh"); //赋值给student实体stuName属性值为"leh";
(3) public static String getProperty(Object bean, String name):
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.(返回带格式的属性值,也可以不带格式,不带格式相当于下面的getSimpleProperty()方法)
eg: String cityPattern = "addresses[0].city";
String city = (String) PropertyUtils.getProperty(customer, cityPattern);
//customer对象中有Address类型,后者有city属性。
(4) public static void setProperty(Object bean, String name, Object value):
(4) public static String getSimpleProperty(Object bean, String name):
eg:BeanUtils.getProperty(student,"stuName"); //得到student实体的stuName属性的值。stuName为student的基本类型;
(5) public static void populate(Object bean, Map properties):
Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.
eg:
Map userMap =hashMap();
userMap.put("stuName","leh");
……
BeanUtils.populate(student,userMap);//将userMap中的键的值赋值给同student中与map的键同名的属性。同名则复制,不同则不赋值。