【发布时间】:2020-10-19 14:01:59
【问题描述】:
我必须像下面的问题那样开发一个端点
/GET Filter_Questions - Returns list of questions based on the combination of following
query parameters
a. Input
i. Companies - List of companies - Optional
ii. Subtopics - List of subtopics - Optional
iii. Likes - Questions with more votes than votes sent as input - Optional
iv. Date - Questions asked after a given date - Optional
v. Tags - List of tags - - Optional
b. Output
i. Question ID
ii. Question Text
iii. Companies - List of companies for which the question was asked
iv. Likes - Number of likes of the question
v. Answer - Answer with most likes for the given question
vi. Tags - Tags associated with the given question
我应该如何处理这个问题,我可以做到这一点的方法是获取列表中的所有问题,然后为所有查询参数制作单独的列表,
如果用户提供 3 个参数,则将创建 3 个列表,然后我将从列表中获取重复项并返回创建的列表
但我觉得必须有一种更清洁的方法来解决这个问题?
【问题讨论】:
-
您绝对应该在单个查询中执行此操作,无需在 Java 端进行过滤。就目前而言,问题是广泛的。查看 JPA、Hibernate 和 Spring Data JPA 文档。然后对问题的一个子集进行编码,也许只有一个用于过滤的列表。这样您就可以自己解决问题,或者提出可以用几段来回答的问题。
标签: mysql spring-boot hibernate spring-data-jpa spring-rest