[英]What's the way you transfer data object from client to server for persisting datas using GWT?
If you use JPA or another kind of persistence, you probably have a way to save a record that is sent to client via ajax. 如果您使用JPA或其他类型的持久性,您可能有办法保存通过ajax发送到客户端的记录。
EDIT : the interface is done with GWT, so all ajax call are classic java method (converted to javascript equivalent) 编辑:接口是用GWT完成的,所以所有ajax调用都是经典的java方法(转换为javascript等价)
Let's take the class Person which is an entity in database. 让我们把类Person作为数据库中的实体。 Person has four fields : name, birthday, id, email
人有四个字段: name, birthday, id, email
When you load a person from server via ajax, you generally send to client a Person object. 当您通过ajax从服务器加载某人时,通常会向客户端发送一个Person对象。
In your Person editor, you display the name, the birthday and the email. 在人物编辑器中,您可以显示姓名,生日和电子邮件。 When the Person object is edited you may want to display the id. 编辑Person对象时,您可能希望显示id。
There are two cases : 有两种情况:
When you send the just edited datas to server, what's the way you proceed ? 将刚刚编辑的数据发送到服务器时,您的进展方式是什么?
I see several approaches : 我看到几种方法:
To summary you have one of the following method signature (just for edit case): 总结一下,您有以下方法签名之一(仅适用于编辑案例):
Person savePerson(Person person);
Person savePerson(String id, String email);
I see pros and cons for each approach. 我看到每种方法的利弊。 For example the first allow quick change on the Person model without modifying all savePerson calls. 例如,第一个允许快速更改Person模型而不修改所有savePerson调用。 But it is less readable than the second approach to know what is really saved. 但它比第二种方法更难以理解什么是真正节省的。
I don't know what is the best one and if you know another way to do that. 我不知道什么是最好的,如果你知道另一种方法。 So, how do you do ? 那么,你好吗?
It is always nice to use domain objects for data transfer. 使用域对象进行数据传输总是很好。 In GWT you have to define your interfaces and mark your Rpc BeanProxies. 在GWT中,您必须定义接口并标记Rpc BeanProxies。 As part of the project evolution, you find a need to add additional fields to an object. 作为项目演变的一部分,您需要向对象添加其他字段。 If you go with interfaces that use data attributes rather than objects, you will be constantly changing them and the method signature becomes clumsy and unreadable. 如果使用的是使用数据属性而不是对象的接口,则会不断更改它们,并且方法签名变得笨拙且不可读。
However, certain people ask for a separation of persistance domain entities from business domain. 但是,某些人要求将持久域实体与业务域分开。 In such cases, property copying (apache commons-bean utils) can be used. 在这种情况下,可以使用属性复制(apache commons-bean utils)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.