简体   繁体   English

Spring Boot+Mysql如何实现数据的版本化?

[英]How do I implement the versioning of the data in Spring Boot + Mysql?

I know how the versions of the record will be saved.我知道如何保存记录的版本。 I chose the "double table" method我选择了“双表”方式

I have a "post" table, and I just need to create another table, exactly the same, and call it "history" .我有一个“post”表,我只需要创建另一个完全相同的表,并将其称为“history” When you change the master record in the "post" table, a copy of the changed entry with a label is created, who changed it and when it is in the "history" table.当您更改“发布”表中的主记录时,会创建一个带有标签的已更改条目的副本,以及更改它的人以及何时在“历史”表中。 在此处输入图片说明

The question is how to implement this in a project that uses a spring boot.问题是如何在使用弹簧靴的项目中实现这一点 If you have any examples or thoughts on how to implement this, please share with me.如果您对如何实现这一点有任何示例或想法,请与我分享。

The Internet describes only the methods themselves, without their solution.互联网只描述方法本身,没有它们的解决方案。


Please help me.请帮我。 If you have any comments then say them.如果您有任何意见,请说出来。

Assuming you are using Spring Data with Spring boot, you can use Hibernate envers' @Audited annotation for Post entity to persist the old value in another table ( here's the documentation), eg:假设您将 Spring Data 与 Spring boot 一起使用,您可以使用 Hibernate envers' @Audited注释Post实体将旧值保留在另一个表中(这是文档),例如:

@Entity
@Audited
public class Post {
..
}

Here are some examples.这里有一些例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM