使用Spring Data REST,我有两个模型,一个是与NvdVulnerabilities具有一对多关系的NvdApps
我正在尝试添加通过NvdApp搜索NvdVulnerabilities的功能,因此我的存储库如下所示:
public interface NvdVulnerabilityRepository extends PagingAndSortingRepository<NvdVulnerability, Long> {
List<NvdVulnerability> findByNvdApp(NvdApp nvdApp);
}这就是我的REST终点:
"findByNvdApp" : {
"href" : "http://localhost:8080/api/nvdVulnerabilities/search/findByNvdApp{?nvdApp}",
"templated" : true
}当我尝试使用这个端点时,它只返回整个表,而不管我在查询字符串中放了什么。我尝试过的示例URL:
http://localhost:8080/api/nvdVulnerabilities/search/findByNvdApp?nvd_app_id=25
http://localhost:8080/api/nvdVulnerabilities/search/findByNvdApp?25
http://localhost:8080/api/nvdVulnerabilities/search/findByNvdApp?NvdApp=25我是否遗漏了一些配置?我基本上是在尝试复制查询:
SELECT * FROM NVD_VULNERABILITY where nvd_app_id = 25它在H2数据库控制台中的工作方式与预期相同。搜索终结点到底是如何工作的,我如何让它按照预期进行过滤?
我还希望使用搜索端点进行分页;现在它返回整个7k+行,而端点http://localhost:8080/api/nvdVulnerabilities/每页返回20个项目
发布于 2020-07-09 06:08:39
您可以尝试:
List<NvdVulnerability> findByNvdApp_Id(Integer id);如果您的NvdApp类中存在Integer id变量。
发布于 2020-07-09 06:26:04
更改存储库查询以匹配以下内容:
public interface NvdVulnerabilityRepository extends PagingAndSortingRepository<NvdVulnerability, Long> {
Page<NvdVulnerability> findByNvdApp_Id(Long id, Pageable pageable);
}允许按id进行搜索以及对返回结果进行分页
https://stackoverflow.com/questions/62804034
复制相似问题