java快速创建dto,java-是否有一种方法(例如Eclipse插件)自动从实体(JPA)生成DTO?

我想要一个简单的DTO生成工具,

>即时生成(例如cglib-动态创建类和DTO对象)

>或将使用Entity并生成DTO的Eclipse插件(用户将指定要包含的树图,对于不包含的树图,则将包含外键而不是相关实体等)

例如.像这样

@Entity

@Table(name="my_entity")

public class MyEntity {

@Id @GeneratedValue(strategy=GenerationType.AUTO)

private Long id;

private String name;

@ManyToOne

private RelatedEntity related;

public RelatedEntity getRelated(){

return related;

}

...

并生成这样的东西:

@Entity

@Table(name="my_entity")

public class MyEntity imlpements MyEntityDTO {

@Id @GeneratedValue(strategy=GenerationType.AUTO)

private Long id;

private String name;

@ManyToOne

private RelatedEntity related;

//overrides MyEntity interface, it's allowed to narrow return type

public RelatedEntity getRelated(){

return related;

}

...

//implements MYEntityDTO respective interfaces

public Long getRelatedId(){return related.getId();}

和DTO接口:

public interface MyEntityDTO {

public String getId();

public String getName();

public Long getRelatedId();

public RelatedEntityDTO getRelated(); //RelatedEntity implements RelatedEntityDTO

...

}

public interface RelatedEntityDTO {

...

}

如果我们不想在图表中包含子项,请从DTO界面中将其删除:

public interface MyEntityDTO {

public String getId();

public String getName();

public Long getRelatedId();

...

我确定有一些eclipse插件,如果没有,我会挑战某人写一个,或者解释为什么我想要的东西没有帮助(并提供替代建议)

解决方法:

标签:dto,eclipse,jpa,code-generation,java

来源: https://codeday.me/bug/20191102/1992962.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值