嘿,我已经和学生一起创建了自己的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.
}
Run Code Online (Sandbox Code Playgroud)
//我创建了一个方法getAll.
我需要另一个人的帮助.
提前致谢.
service.xml您首先需要在您定义的实体中将其声明为“finder”元素。
例如
<finder name="Name" return-type="Student">
<finder-column name="name" />
</finder>
Run Code Online (Sandbox Code Playgroud)
如果名称不唯一,也可能需要 a 作为返回return-type类型Collection。List<Student>
<finder name="Name" return-type="Collection">
<finder-column name="name" />
</finder>
Run Code Online (Sandbox Code Playgroud)
您还可以为列指定比较运算符:
<finder name="NotName" return-type="Collection">
<finder-column name="name" comparator="!=" />
</finder>
Run Code Online (Sandbox Code Playgroud)
unique="true"查找器实际上可以通过在查找器上指定属性来声明要在此关系上生成的唯一索引(将应用于数据库表) :
<finder name="Name" return-type="Student" unique="true">
<finder-column name="name" />
</finder>
Run Code Online (Sandbox Code Playgroud)
使用此定义并重新运行后,ant build-service将studentPersistence包含使用在 xml 元素中找到的查找器名称并附加前缀的新方法:countBy、findBy、fetchBy、removeBy 等。
最后,您的服务方法只需要包含以下内容(基于上述内容):
public Student getStudentByName(String name) throws SystemException {
return studentPersistence.findByName(name);
}
Run Code Online (Sandbox Code Playgroud)
华泰
| 归档时间: |
|
| 查看次数: |
668 次 |
| 最近记录: |