1

RequestContext@Entity注釈付きクラスの外部にメソッドを実装することは可能ですか?

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

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

1 に答える 1

2

はい、できます。これは公式のGWTドキュメントに記載されていますが、あまり詳細ではありません。

DavidChandlerによるこのブログ投稿に大きな助けがありました。

いくつかのポインタ:(
リンクの例はブログ投稿で説明されているプロジェクトからのものです)

エンティティロケーターメソッドfind、、、、 )はcreate、汎用Locatorクラス(getId)でgetVersion移動できます。これを機能させるには、エンティティがandメソッドを持つBasicEntityクラスを拡張する必要があります。次に、クライアントで次のようにロケーターを指定します。getIdgetVersion

@ProxyFor(value = MyEntity.class, locator = GenericLocator.class)
public interface MyEntityProxy extends EntityProxy {
...
}


データアクセス方法は、サービス内で移動できます。汎用サービス()を作成し、それをエンティティごとに拡張して、特定のメソッドを提供することができます()。

クライアントでは、次のようにサービスを定義します。

// 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);
... 
}

サービスロケーターの必要性にも注意してください。これと同じくらい簡単にすることができます。

于 2011-10-03T17:45:37.540 に答える