将ArrayLists与EO(实体对象)转换为DTO对象的ArrayLists或Ids的ArrayLists的最有效方法是什么?请记住,每个EO可能包含也是EO的属性,或EO的集合,这些集合应在内部转换为DTO,或省略(取决于转换策略)。一般来说,有很多样板代码。将集合从一种类型转换为另一种类型的策略
希望它是那么简单:
collectionOfUsers.toArrayList<UserDTO>();
或..
collectionOfUsers.toArrayList<IEntity>();
// has only an id, therefore it will be converted
// into a collection of objects, having only an id.
当然
,这可能是不错的还有:
collectionOfUsers.toArrayList<Long>()
// does the same thing, returns only a bunch of ids
当然,有人要也要保持映射策略,例如Factory或者某事物。
有什么建议吗?