【发布时间】:2011-07-18 12:50:42
【问题描述】:
将带有EO(实体对象)的ArrayLists转换为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
当然,映射策略也应该有人掌握,例如工厂或某事。
有什么建议吗?
【问题讨论】: