是否可以在 @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 有很大帮助作者:大卫·钱德勒。
一些提示:
(示例链接来自博客文章中讨论的项目)
实体定位器方法(find
、create
、getId
、getVersion
)可以在通用 Locator 类 ( example ) 中移动。为此,您的实体必须扩展具有 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);
...
}
还要注意服务定位器的需要。它可以像this一样简单.
关于java - GWT - 如何在 @Entity 注释的类之外实现 RequestContext 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7625987/