保持验证逻辑同步服务器和客户双方 [英] Keeping validation logic in sync between server and client sides

查看:69
本文介绍了保持验证逻辑同步服务器和客户双方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 previous问题大多数评论者同意双方在客户与放有验证逻辑;服务器端是一件好事。

In my previous question most commenters agreed that having validation logic both at client & server sides is a good thing.

但是有一个问题 - 你需要保持你的验证规则同步数据库和客户端code之间。

However there is a problem - you need to keep your validation rules in sync between database and client code.

所以,问题是我们如何能处理呢?

So the question is how can we deal with it ?

的一种方法是使用ORM技术,现代ORM工具可以产生code,可以照顾数据验证之前将其发送到服务器。

One approach is to use ORM techniques, modern ORM tools can produce code that can take care of data validation prior sending it to the server.

我很愿意听取你的意见。

你有某种标准流程来处理这个问题呢?或者,也许你认为这是不是有问题呢? :)

I'm interested in hearing your opinions.
Do you have some kind of standard process to deal with this problem? Or maybe you think that this is not a problem at all? :)

修改

大家好,首先感谢您的答案。

Guys, first of all thank you for your answers.

明天我会在这案例

推荐答案

由于在回答其他职位之一提到的,如果你要保持你的分层,有避免重复验证逻辑没有什么好办法在每一层。如果你使用的东西自动绑在一起,你都推出了一种可能妨碍你在路上层与层之间的耦合。这可能是这些情况下,你就必须跟踪手动的事情之一。

As mentioned in one of the answers to the other post, if you are going to keep your layers separated, there is no good way to avoid duplicating the validation logic in each layer. If you use something to automatically tie them together, you have introduced a sort of coupling between the layers that might hinder you down the road. This might be one of those cases where you just have to keep track of things manually.

不过你去,你必须确保每一层做它自己的验证,因为你永远不知道层将如何进行访问。有没有保证你实现的所有图层将永远呆在一起。

However you go about it, you have to make sure each layer is doing its own validation, because you never know how that layer is going to be accessed. There's no guarantee that all the layers you implemented will always stay together.

这篇关于保持验证逻辑同步服务器和客户双方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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