有没有办法(例如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插件,如果没有,我会挑战某人写一个,或者解释为什么我想要的东西没有帮助(并提供替代建议)     
已邀请:
也许Hibernate Tools应该这样做:http://hibernate.org/subprojects/tools.html     
Telosys Tools可以生成:JPA实体和DTO 让我们看一下本教程https://sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa 它使用JPA生成完整的Spring MVC CRUD应用程序 架构:https://sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa/presentation/architecture 映射器Entity / DTO也会生成(它使用\“ org.modelmapper \”) 模板是可定制的     
尝试看看: https://github.com/nikelin/spring-data-generation-kit 但这仅适用于您的项目在 Maven控制。     

要回复问题请先登录注册