gpt4 book ai didi

java - GWT 保持客户端和服务器模型同步

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:27:04 24 4
gpt4 key购买 nike

当用户访问网站时,会在客户端和服务器端创建一个空的购物车。当他将产品添加到 SC 时,会执行 RPC 调用以在服务器端添加产品。我们需要做相同的客户端以同步并更新 UI。如果我们不这样做,则切换到引用旧 SC 的 View 。 UI 不会相应更新(空 SC,但其中有一个产品)。

解决方案一

RPC 调用返回更新后的 SC 并执行 clientSC = returnedSC。它不是很有效,因为需要通过网络传输大量数据。

方案二

RPC 调用返回添加的产品,并在客户端调用 addProduct 方法将产品添加到列表中,而不是将其存储在数据存储中(如在服务器端)。

方案三

与解决方案 2 相同,但使用事件通知具有 SC 引用的演示者(我使用 MVP 模式)。

哪个最好,更一般地说,保持客户端和服务器模型同步的最佳实践是什么?

最佳答案

使用随 gwt 2.1 一起提供的 RequestFactory。

http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html

RequestFactory makes it easy to implement a data access layer on both client and server. It allows you to structure your server-side code in a data-centric way and provides a higher level of abstraction than GWT-RPC, which is service-oriented rather than data-oriented. On the client side, RequestFactory keeps track of objects that have been modified and sends only changes to the server, which results in very lightweight network payloads. In addition, RequestFactory provides a solid foundation for automatic batching and caching of requests in the future.

RequestFactory uses its own servlet, RequestFactoryServlet, and implements its own protocol for data exchange between client and server. It is not designed for general purpose services like GWT-RPC, but rather for data-oriented services as we will see shortly. RequestFactory does not use GWT-RPC and is not intended to replace it. It is designed specifically for implementing a persistence layer on both client and server.

关于java - GWT 保持客户端和服务器模型同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4414446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com