禁止用户编辑同一条记录 [英] Prevent user from editing the same record

查看:73
本文介绍了禁止用户编辑同一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL&在同一网络上开发多用户应用程序; Java. 我正在寻找的是: 用户A:修改记录100 用户B:尝试查看或修改100条相同的记录.

I'm developing a Multiple user application on same network usign MySQL & Java. What I'm looking for is: User A: Modifying Record 100 User B: Try to view or modify same record 100.

我希望应用程序返回用户B的错误消息,该记录已被另一个用户编辑.

I want the application to return error message for User B, that record already editing by another user.

我该怎么做?

推荐答案

在您要防止多个用户更新的数据库表中包含一个 edit_timestamp ,每次有人更新时,您都会对其进行更新编辑行.

Include an edit_timestamp in the tables of your database you want to prevent from multiple users updating, which you'll update every time anyone edit the row.

在表单中,包括一个隐藏字段 edit_timestamp ,其值存储在您要编辑的行中.

In your forms, include a hidden field edit_timestamp with the value stored in the row you're editing.

当您收到编辑表单时,请检查您正在编辑的行的 edit_timestamp 是否没有更改.如果已更改,则有人编辑了该行并向用户抛出错误.如果没有更改,请更新该行和 edit_timestamp 字段

When you receive a edit form, check if the edit_timestamp of the row that you're editing hasn't changed. If it has changed, someone has edited the row and throw an error to the user. If it hasn't changed, update the row and the edit_timestamp field

这篇关于禁止用户编辑同一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆