将实体元素添加到同一元素 - @OneToMany

我将Task实体表示为:


@Entity

@Getter

@NoArgsConstructor

public class Task {

    @Id

    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private long id;

    @NotBlank

    private String name;

    @Enumerated(EnumType.STRING)

    private Category category;

    @OneToOne

    private Employee assignee;

    @OneToMany

    private List<Task> precedingTasks;

    private String details;

    private int estimatedTimeInMinutes;

    private LocalDateTime deadline;

    private LocalDateTime creationTime;

    private LocalDateTime startTime;

    private LocalDateTime endTime;


    public Task(String name, Category category, Employee assignee, List<Task> precedingTasks, String details,

                int estimatedTimeInMinutes, LocalDateTime deadline) {

        this.name = name;

        this.category = category;

        this.assignee = assignee;

        this.precedingTasks = precedingTasks;

        this.details = details;

        this.estimatedTimeInMinutes = estimatedTimeInMinutes;

        this.deadline = deadline;

        this.creationTime = LocalDateTime.now();

        this.startTime = null;

        this.endTime = null;

    }

我注意到没有precedingTasks正确添加任务,但没有正确添加。


例如:添加三个任务后,precedingTasks我没有POST在 Postman 中发送,如下所示:


{

    "name": "Wyslac przesyłke nr 87",

    "category": "TODO",

    "assigneeId": 1,

    "precedingTasksId": [1, 2, 3],

    "details": "Dodac zakladke",

    "estimatedTimeInMinutes": 78,

    "deadline": "2013-12-18T14:30:40.100000000"

}

但我得到的任务没有preceding tasks:


{

    "id": 4,

    "name": "Wyslac przesyłke nr 87",

    "category": "TODO",

    "assignee": {

        "id": 1,

        "firstName": "Wojciech",

        "lastName": "Wasilewski",

        "email": "wojtek@wasilewski.pl",

        "role": "ADMIN",

        "password": "h*n$GvFE",

        "manager": true,

        "password_LENGTH": 8,

        "passwordValid": false

    },

 


芜湖不芜
浏览 125回答 2
2回答

慕斯王

您的类TaskRequest中的字段之前的TaskIds在名称上与您的 POST 请求中的之前的TasksId中的字段不对应。在 Postman 中重命名或重写 POST。

慕工程0101907

您发布“precedingTasksId”,但该类需要“precedingTasksIds”。似乎这只是一个错字。让我知道这是否有效。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java