Java @RepositoryRestResource中的自定义实现
我正在从事一个使用Java @RepositoryRestResource中的自定义实现,java,rest,spring-boot,jpa,Java,Rest,Spring Boot,Jpa,我正在从事一个使用@RepositoryRestResource的springboot项目 有两个实体,产品和领域,它们具有多对多关系 我想实现一个正在运行复杂查询的自定义REST调用 要实现自定义实现,我将遵循以下步骤 产品存储库界面: @RepositoryRestResource(collectionResourceRel = "product", path = "product") public interface ProductRepository extends CrudReposi
@RepositoryRestResource
的springboot项目
有两个实体,产品
和领域
,它们具有多对多关系
我想实现一个正在运行复杂查询的自定义REST调用
要实现自定义实现,我将遵循以下步骤
产品存储库界面:
@RepositoryRestResource(collectionResourceRel = "product", path = "product")
public interface ProductRepository extends CrudRepository<Product, Long>, CustomProductRepository {
List<Product> findByName(@Param("name") String name);
}
即使我打电话休息,我也会得到404
我错过了什么
谢谢。显然,这是设计不可能的。但是,如果使用
@Query
进行注释,则自定义方法可以工作。
请参见如果您有IntelliJ IDE,请在底部选项卡中检查spring组件,并查看您的路径是否在那里列出…@silentsudo,我正在使用IntelliJ,但不确定在哪里可以看到spring组件。你能给我指一下指南吗?它能帮我吗?你需要编写一个控制器来监听你正在命中的端点。@joemokenela,这不会违背使用
RepositoryRestResource
的目的,我们不必编写控制器吗?请参阅
public interface CustomProductRepository {
public List<Product> findByDomainName(String domainName);
}
public class ProductRepositoryImpl implements CustomProductRepository {
@Override
public List<Product> findByDomainName(long id, String domainName) {
List<Product> result = new ArrayList<>();
// Query logic goes here
return result;
}
}
@RepositoryRestResource(collectionResourceRel = "product", path = "product")
public interface ProductRepository extends CrudRepository<Product, Long>, CustomProductRepository {
List<Product> findByName(@Param("name") String name);
}
{
"_links" : {
"findByName" : {
"href" : "http://localhost:8080/product/search/findByName{?name}",
"templated" : true
},
"self" : {
"href" : "http://localhost:8080/product/search/"
}
}
}