我正在尝试将自定义方法添加到我的Spring Data存储库PersonRepository,如1.3 Spring Data存储库的自定义实现中所述,并通过REST公开这些方法.初始代码来自使用REST示例访问JPA数据,以下是添加/修改类的代码:
interface PersonRepositoryCustom {
List<Person> findByFistName(String name);
}
class PersonRepositoryImpl implements PersonRepositoryCustom, InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
// initialization here
}
@Override
public List<Person> findByFistName(String name) {
// find the list of persons with the given firstname
}
}
@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findByLastName(@Param("name") String name);
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序并访问时http://localhost:8080/portfolio/search/,我得到以下响应正文:
{
"_links" : {
"findByLastName" …Run Code Online (Sandbox Code Playgroud)