为基于 Java 的 Web 应用程序实现文章修订历史记录
关于如何最好我可以为基于 Java 的 Web 应用程序实现文章修订历史并将其保存在 AuditLog
StackOverflow 中的任何想法都已经具有这样的功能,允许人们看到一个版本与另一个版本的差异,几乎像 SVN客户。
这更多的是一个设计问题而不是实现问题。
另外:如何在网页上显示这些更改?
另外:建议的解决方案
Article
--------------------------------
Integer id
String title
String body
List<Tag> tags
AppUser createdBy
Date createdDate
AuditLog
--------------------------------
Integer id
Integer objectId
Operation operation // enum with UPDATE and DELETE. I won't audit an insert
Date createdDate
AppUser createdBy
String class
String revisionXML
String comment
A Hibernate Interceptor 会拦截 保存过程并使用 Castor XML 创建旧对象。
类和 ID 用于获取特定对象的修订版本。
将使用 google-diff-match-patch用于创建 HTML diff 文件
Any ideas of how best i can implement article revision history for a Java based web application and save it in AuditLog
StackOverflow already has such a feature allowing one to see the differences from one version to another, almost like SVN clients.
This is more of a design than implementation question.
addition: How would one display these changes on the web page?
addition: Proposed solution
Article
--------------------------------
Integer id
String title
String body
List<Tag> tags
AppUser createdBy
Date createdDate
AuditLog
--------------------------------
Integer id
Integer objectId
Operation operation // enum with UPDATE and DELETE. I won't audit an insert
Date createdDate
AppUser createdBy
String class
String revisionXML
String comment
A Hibernate Interceptor will intercept
the save process and use Castor XML to create an XML string of the old object.
The class and id is used to get the revisions of a particular object.
google-diff-match-patch will be used for creating HTML diff files
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的解决方案是使用已经支持版本的数据库或存储,例如 Apache Jackrabbit。
如果这不是一个选项,那么您必须决定要将文章存储在哪里。在文件系统上?然后将每篇文章建立一个目录,并将修订版本保存为编号(00001、00002 等),并将最后修订版本的编号放入一个特殊文件(如
current
)中。然后您可以快速找出有多少个版本(只需查看当前
)并前进和后退。如果您使用数据库,则将版本号字段添加到文章表中,并添加第二个表或一个标志来说明当前版本是哪个版本。您还可以使用
max(version)
进行选择,但这些 SQL 构造往往非常丑陋且令人困惑。将此信息保存在其他地方要简单得多。[编辑] 要生成差异,请查看此项目:google-diff-match-补丁
The best solution would be to use a database or storage which already supports versions, for example Apache Jackrabbit.
If that's not an option, then you must decide where you want to store the articles. On the file system? Then make each article a directory and save the revisions as numbers (00001, 00002, etc.) and put the number of the last revision in a special file (like
current
). Then you can quickly find out how many versions there are (just look intocurrent
) and go forward and back.If you use a database, then add a version number field to the article table and add a second table or a flag which says which one the current version is. You could also select with
max(version)
but those SQL constructs tend to be pretty ugly and confusing. It's much more simple to save this information elsewhere.[EDIT] To generate diffs, look at this project: google-diff-match-patch
我会在后台使用现有的 VCS(例如 SVN)。那里有修订历史记录 - 剩下要做的就是从您的应用程序到 VCS 的接口。
I would use an existing VCS (for instance, SVN) under the hood. There you have the revision history - all that's left to make is an interface from your app to the VCS.