相关疑难解决方法(0)

实现Spring Data存储库的自定义方法并通过REST公开它们

我正在尝试将自定义方法添加到我的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)

java rest spring jpa spring-data

44
推荐指数
3
解决办法
3万
查看次数

标签 统计

java ×1

jpa ×1

rest ×1

spring ×1

spring-data ×1