本文介绍了Spring Boot从MySQL创建记录重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据记录

实体在主键中给出如下

@GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id",unique = true,nullable = false)
    public Long id;

我尝试过的方法甚至使用对象映射器尝试过的方法

what i have tried and even tried with object mapper which has some other issues

Record abc =dao.findById(11);
abc.setId(Null); //not working  
dao.save(abc) //not working

推荐答案

您应该创建一个新对象:

you should create a new object:

Record abc =dao.findById(11);
Record def = new Record(abc);
dao.save(def)

在Record类中,您应该具有这样的构造函数:

and in Record class, you should have a constructor like this:

public Record(){}
public Record(Record rec){
    this.field1 = rec.field1;
}

这篇关于Spring Boot从MySQL创建记录重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 23:58