Java BeanUtils - 转换集合
描述
借助 Transformer 接口,commons-collections 中支持从输入对象到输出对象的转换。 借助 Commons-collections 中可用的代码,可以应用 Transformer 从输入集合中获取输出集合。 BeanToPropertyTransformer 是将 bean 转换为其属性值的 Transformer 示例。 此功能能够从输入对象中提取特定属性并将其呈现为输出对象。
如果您尝试从集合中的许多汽车用户中找出特定的汽车型号。 语法如下所示:
// creating transformer BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer( "person.company.carmodel" ); // transforming Collection Collection carModel = CollectionUtils.collect( peopleCollection, transformer );