问题描述
我有两个集合对象Set<Foo> fooSet
和Set<Bar> barSet
。 Foo
是实体对象,Bar
是我要用于将数据发送到UI的DTO。我要将所有属性从fooSet
复制到barSet
。
public class Foo {
@Id
@Column(name = "Category_Id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long categoryId;
@OneToMany(mappedBy="productCategory")
private Set<ProductEntity> products;
}
public class BarDto {
private Long categoryId;
private Set<ProductDto> products;
}
我正在尝试将Entity转换为DTO对象,例如:
public BarDto mapDomainToDto(Foo domain) {
BarDto barDto= new BarDto();
barDto.setCategoryId(domain.getCategoryId());
//trying to do something like:
barDto.setProducts(domain.getProducts());
}
在Java 8中有什么方法可以实现这一目标?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)