spring启动后写空值(db)

vuv7lop3  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(137)

我已经修复了“不支持的媒体类型”更改注解的问题 @RequestBody 带注解 @ModelAttribute . 现在il工作了,但是t在db处发送空值。
我的calss便条

@Entity
@Table(name = "note")
public class Note {

    private @Id @GeneratedValue Long idNote;

    private String content;

    private String title;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user", insertable = false, updatable = false)
    @Fetch(FetchMode.JOIN)
    @JsonManagedReference(value = "user")
    private User user;

    public Note(){}

    public Note(Long id, String content, String title,User user ){
        this.idNote = id;
        this.content = content;
        this.title = title;
        this.user= user;
    }

我的类用户

@Entity
@Table(name = "user")
public class User {

    private @Id @GeneratedValue @Column int idUser;
    private String name;
    private String surname;
    @OneToMany(targetEntity = Note.class, mappedBy = "idNote", orphanRemoval = false, fetch = 
    FetchType.LAZY)
    @JsonManagedReference(value = "note")
    private Set<Note> notes;

    public User() {}

    public User(int idUser, String name, String surname, Set<Note> notes) {
        this.idUser = idUser;
        this.name = name;
        this.surname = surname;
        this.notes = notes;
    }

我的post方法

//REQUEST BODY
    @PostMapping(path="body", consumes = MediaType.APPLICATION_JSON_VALUE)
    void ResponseBodyPost(@ModelAttribute Note note){
        noteService.requestBodyCU(note);
    }

在《 Postman 》中,我对这具尸体提出了要求:

{
    "content": "content8",
    "title": "title8",
    "user": 2
}

在db中,我只有note id值:

{
    "idNote": 14,
    "content": null,
    "title": null,
    "user": null
}

我已经将content type设置为application/json。我不明白我的问题是什么,我有两天的时间来解决这个问题

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题