9

ねえ、学生と一緒に独自のservice.xmlを作成しました。ここで、生徒用に独自の searchByName メソッドを追加したいと考えています。StudentLocalServiceImpl に何を書くべきか教えてください。

 public class StudentLocalServiceImpl extends StudentLocalServiceBaseImpl {
/*
 * NOTE FOR DEVELOPERS:
  *
 */

public List<Student> getAll() throws SystemException {
    return studentPersistence.findAll();
}

public Student getStudentByName(String name) {
    return studentPersistence.
}

// getAll メソッドを 1 つ作成しました。
私は別のもののために助けが必要です。
前もって感謝します。

4

1 に答える 1

4

service.xml最初に、定義したエンティティ内でこれを「ファインダー」要素として宣言します。

例えば

<finder name="Name" return-type="Student">
    <finder-column name="name" />
</finder>

name が一意でない場合、戻り値の型としてaがreturn-type必要な場合もあります。CollectionList<Student>

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

列の比較演算子を記述することもできます。

<finder name="NotName" return-type="Collection">
    <finder-column name="name" comparator="!=" />
</finder>

unique="true"ファインダーは、ファインダーで属性を指定することにより、このリレーションで生成される (DB テーブルに適用される) 一意のインデックスも宣言できます。

<finder name="Name" return-type="Student" unique="true">
    <finder-column name="name" />
</finder>

この定義を使用して再実行ant build-serviceするstudentPersistenceと、xml 要素で見つかったファインダーの名前に接頭辞 (countBy、findBy、fetchBy、removeBy など) を追加した新しいメソッドが含まれます。

最後に、serice メソッドには次のもののみを含める必要があります (上記に基づく)。

public Student getStudentByName(String name) throws SystemException {
    return studentPersistence.findByName(name);
}

HTH

于 2012-11-30T18:48:35.963 に答える