0

本を追加/更新/削除し、著者を追加できるポートレットがあります。さらに、本を追加しようとすると、既存の著者を選択できます。

ここに画像の説明を入力

次に、各著者が何冊の本を書いたかを「著者」テーブルに表示する必要があります。どうすればいいですか?私はliferayの初心者で、まったくわかりません。

それは私のservice.xmlです

<entity name="Book" local-service="true" remote-service="true"  cache-enabled="false">

    <column name="bookId" type="long" primary="true" />
    <column name="bookName" type="String" />
    <column name="bookDescription" type="String" />
    <column name="authors" type="Collection" entity="Author" mapping-table="Books_Authors" />
    <finder return-type="Collection" name="bookName">
        <finder-column name="bookName"></finder-column>
    </finder>

</entity>

<entity name="Author" local-service="true" remote-service="true" cache-enabled="false">
    <column name="authorId" type="long" primary="true" />
    <column name="authorName" type="String" />
    <column name="books" type="Collection" entity="Book" mapping-table="Books_Authors" />

</entity>
4

1 に答える 1

3

Service Builder はあなたの友達です。

の書籍エンティティにファインダーを追加するだけですservice.xml。エンティティに という名前のフィールドがある場合author:

<finder name="Author" return-type="Collection">
    <finder-column name="author" />
</finder>

build-service を実行すると、メソッドBookUtil.findByAuthor()とが生成されますBookUtil.countByAuthor()

で対応するメソッドを実装しBookLocalServiceImpl、前のメソッドを呼び出して、build-service をもう一度実行すると、クラスで使用できるようになりますUtil。何かのようなもの

public List<Book> getByAuthor(String author) {
    return getPersistence().findByAuthor(author);
}

public int countByAuthor(String author) {
    return getPersistence().countByAuthor(author);
}

build-service を最後に呼び出した後、 からそれらを呼び出すことができますBookLocalServiceUtil

カウントだけが必要な場合は、すべてのコレクションを取得しないでください。多くのレコードがある場合、それは悪い考えです。代わりにカウントを呼び出します。

于 2016-09-05T15:08:59.493 に答える