如何在Java中的对象中映射set()?

发布于 2025-01-18 04:09:14 字数 1832 浏览 1 评论 0原文

我在具有1组的对象中有1个对象。当数据从API传输并从数据库中获取数据时,我们如何映射2集<>一起?目前,我在错误的时间在正确的时间绘制结果。因为每次请求数据时,设置的排序都不同,这会导致设置请求的顺序并设置为偏斜,并且地图不能。

请求的示例JSON:

{
"id": "4028828d",
"facilityResults": [
    {
        "id": "4024decaa62003b",
        "value": "1",
        "note": "hau nha 656251"
    },
    {
        "id": "4028828d7f003c",
        "value": "12"
        "note": "hy 52s"
    }
]}

executeCheckList

public class ExecuteChecklist extends SiteBaseHest {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private String id;

    @Column(name = "code", length = 20)
    private String code;

    @Column(name = "area_aft", length = 100)
    private String areaAft;

    @OneToMany(mappedBy = "executeChecklist")
    @EqualsAndHashCode.Exclude
    @JsonManagedReference
    private Set<ChecklistStepRst> checklistStepRst; }

executechecteCheckListupDatesdto

public class ExecuteChecklistUpdatesDTO{

    @NotBlank(message = "id can not be null or empty")
    @Size(max = 32, message = "id length must be less than or equal 32 characters")
    private String id;

    @Size(max = 20, message = "code length must be less than or equal 20 characters")
    private String code;

    @Size(max = 100, message = "area length must be less than or equal 100 characters")
    private String areaAft;

    private Set<ChecklistStepRstUpdatesDTO> checklistStepRstUpdatesDTO; }

i To Map()set&lt;清单steprstupdatesdto&gt; ChatlistStePrstupDatesdto;set&lt;清单Steprst&gt;清单steprst;

,但是当JSON更改传递的值时,其排序将更改。放弃错误:

...实例的标识符从x更改为y(x to:id,y to:id be:id)

I have 1 Object in Object which has 1 set. When the data is transmitted from the API and the data is taken from the database, how can we map 2 sets<> together? Currently, I map the results at the right time at the wrong time. Because each time data is requested, set is ordered differently, which causes the order of set request and set to be skewed and the map cannot be.

Example JSON of request:

{
"id": "4028828d",
"facilityResults": [
    {
        "id": "4024decaa62003b",
        "value": "1",
        "note": "hau nha 656251"
    },
    {
        "id": "4028828d7f003c",
        "value": "12"
        "note": "hy 52s"
    }
]}

ExecuteChecklist

public class ExecuteChecklist extends SiteBaseHest {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private String id;

    @Column(name = "code", length = 20)
    private String code;

    @Column(name = "area_aft", length = 100)
    private String areaAft;

    @OneToMany(mappedBy = "executeChecklist")
    @EqualsAndHashCode.Exclude
    @JsonManagedReference
    private Set<ChecklistStepRst> checklistStepRst; }

ExecuteChecklistUpdatesDTO

public class ExecuteChecklistUpdatesDTO{

    @NotBlank(message = "id can not be null or empty")
    @Size(max = 32, message = "id length must be less than or equal 32 characters")
    private String id;

    @Size(max = 20, message = "code length must be less than or equal 20 characters")
    private String code;

    @Size(max = 100, message = "area length must be less than or equal 100 characters")
    private String areaAft;

    private Set<ChecklistStepRstUpdatesDTO> checklistStepRstUpdatesDTO; }

I want to map() Set< ChecklistStepRstUpdatesDTO > checklistStepRstUpdatesDTO; and Set< ChecklistStepRst > checklistStepRst;

But when JSON changes the value passed, its sort is changed. give up error :

identifier of an instance of ... was altered from X to Y ( X to be: id, Y to be: id )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携余温的黄昏 2025-01-25 04:09:14

@bohemian

{
"id": "4028828d",
"facilityResults": [
    {
        "id": "4024decaa62003b",
        "value": "1",
        "note": "hau nha 656251"
    },
    {
        "id": "4028828d7f003c",
        "value": "12"
        "note": "hy 52s"
    }
]}

i map()with:

{
"id": "4028828d",
"facilityResults": [
    {
        "id": "4028828d7f003c",
        "value": "12",
        "note": "hy 52s"
    },
    {
        "id": "4024decaa62003b",
        "value": "1"
        "note": "hau nha 656251"
    }
]}

从数据库上传和检索时的设施results()的顺序是不同的,我不能一起映射()它们

@Bohemian

{
"id": "4028828d",
"facilityResults": [
    {
        "id": "4024decaa62003b",
        "value": "1",
        "note": "hau nha 656251"
    },
    {
        "id": "4028828d7f003c",
        "value": "12"
        "note": "hy 52s"
    }
]}

I map() with:

{
"id": "4028828d",
"facilityResults": [
    {
        "id": "4028828d7f003c",
        "value": "12",
        "note": "hy 52s"
    },
    {
        "id": "4024decaa62003b",
        "value": "1"
        "note": "hau nha 656251"
    }
]}

The order of facilityResults() when uploading and retrieving from the database is different and I can't map() them together

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文