是的你可以。这在官方GWT 文档中有所提及,但不是很详细。
我发现David Chandler的这篇博文对我有很大帮助。
一些提示:(
示例链接来自博客文章中讨论的项目)
实体定位器方法( find
, create
, getId
, getVersion
) 可以在通用 Locator 类 (示例) 中移动。为此,您的实体必须扩展具有getId
和getVersion
方法的 BasicEntity 类。然后在客户端上,您将像这样指定定位器:
@ProxyFor(value = MyEntity.class, locator = GenericLocator.class)
public interface MyEntityProxy extends EntityProxy {
...
}
数据访问方法可以在服务中移动。您可以拥有一个通用服务(example),然后扩展它为每个实体提供特定的方法(example)。
在客户端上,您可以像这样定义您的服务:
// MyEntityDao is your server service for MyEntity
@Service(value = MyEntityDao.class, locator = MyServiceLocator.class)
interface MyEntityRequestContext extends RequestContext {
Request<List<MyEntityProxy>> listAll();
Request<Void> save(MyEntityProxy entity);
...
}
请注意还需要服务定位器。它可以像这样简单。