具有多表的SpringBoot DTO和ModelMapper

问题描述

我是Spring和Java的新手,实际上不使用DTO。

我有一个包含3个表的数据库(使用来自CategorieNamespace和servicesnamespaces的外键进行checkconfigdeploiement)

表: CategorieNamespace,servicesnamespaces,checkconfigdeploiement之类的:

@Entity
@Table(name = "categorienamespaces")
public class CategorieNamespace extends Content {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Integer id;
    private String namespacename;
    private String dateajout;
....
}

@Entity
@Table(name = "servicesnamespaces")
public class ServicesNamespace extends Content {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Integer id;
    private String servicename;
    private String dateajout;
....
@Entity
@Table(name = "checkconfigdeploiement")
public class CheckConfigDeploiementObjectInsertion {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @NotNull(message = "IdNamespace ne peut être vide")
    @Column(name = "idnamespace",nullable = false)
    private Integer idnamespace;

    @NotNull(message = "IdServiceNamespace ne peut être vide")
    @Column(name = "idservicenamespace",nullable = false)
    private Integer idservicenamespace;

    @NotEmpty(message = "Typeverification ne peut être NUL")
    @Column(name = "typeverification",nullable = false)
    private String typeverification;

    @NotEmpty(message = "Status ne peut être vide")
    @Column(name = "status",nullable = false)
    private String status;

    @Column(name = "statuscomplementaire")
    private String statuscomplementaire;

    @Column(name = "details")
    private String details;

    @Column(name = "actionby")
    private String actionby;

    @NotEmpty(message = "ReportDate ne peut être vide")
    @Column(name = "reportdate",nullable = false)
    private String reportdate;
....

那怎么了? 问题是我实际上有2个存储库,一个用于写入,一个用于通过数据库读取数据。是的,现在我知道我不应该这样做,这就是为什么我在这里学习。

能给我提供一些可以帮助我在目标中使用DTO的东西吗? 我从POST控制器收到了类似的对象:

public class CheckConfigDeploiementObjectRecu {

    private String namespace;
    private String composant;
    private String typeverification;
    private String status;
    private String statuscomplementaire;
    private String details;
    private String actionby;
    private String reportdate;
...
}

我需要将其转换为CheckConfigDeploiementObjectInsertion类,以将数据插入数据库。 我认为我应该使用DTO和modelmapper,但我只是没有到达。 感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)