java - GWT - 如何在 @Entity 注释的类之外实现 RequestContext 方法?

标签 java gwt requestfactory gwt-2.4

是否可以在 @Entity 注解的类之外实现 RequestContext 方法?

@Entity
class TheEntity {
  public static TheEntity theMethod() { ... } // don't want it here
}

@Service(TheEntity.class)
interface TheEntityRequest extends RequestContext {
  Request<TheEntity> theMethod(); // this one
}

最佳答案

是的,可以。官方GWT documentation中提到了这一点,虽然不是很详细。

我发现这个 blog post 有很大帮助作者:大卫·钱德勒。

一些提示:
(示例链接来自博客文章中讨论的项目)

实体定位器方法(findcreategetIdgetVersion)可以在通用 Locator 类 ( example ) 中移动。为此,您的实体必须扩展具有 getIdgetVersion 方法的 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);
... 
}

还要注意服务定位器的需要。它可以像this一样简单.

关于java - GWT - 如何在 @Entity 注释的类之外实现 RequestContext 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7625987/

相关文章:

java - 使用 Java mousePress、mouseMove 和 mouseRelease 进行单击和拖动

java - 在Java中查找最大组合总数

java - 从字符串中提取 double 值获取 java.util.NoSuchElementException

java - 在 GWT 中展开 TreeItem

java - 如何使用 RequestFactory : . with(propertyRefs) 组合对象

android - 如何在 Android SyncAdapter 中使用 GWT-RequestFactory(总是出现 ValidationTool-Error)

java - 多 :Threading - Is this the right approach?

java - 在 jsni 函数中调用 GWT java 方法

java - GWT 2.4 应用程序找不到我的 CSS 文件,其类正在通过 UIObject.addStyleName 在代码中使用

java - GWT >2.4 RequestFactory 不保存子对象更改