Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 基于可选查询参数返回列表_Mysql_Spring Boot_Hibernate_Spring Data Jpa_Spring Rest - Fatal编程技术网

Mysql 基于可选查询参数返回列表

Mysql 基于可选查询参数返回列表,mysql,spring-boot,hibernate,spring-data-jpa,spring-rest,Mysql,Spring Boot,Hibernate,Spring Data Jpa,Spring Rest,我必须开发一个端点,如下面的问题所示 /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 - Q

我必须开发一个端点,如下面的问题所示

/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个列表,然后我将从列表中获取重复项并返回创建的列表


但我觉得必须有一种更干净的方法来实现这一点?

您可以使用Spring数据规范等进行可选过滤。创建一个自定义规范类,该类基于给定的筛选器值添加联接和谓词


然后,Spring数据存储库接受该规范作为参数,并使用一个实体图来获取您提到的所有关联,或者使用DTO投影仅获取相关数据。

您应该在单个查询中完成这一操作,而无需在Java端进行筛选。就目前而言,这个问题涉及面很广。看看JPA、Hibernate和Spring数据JPA文档。然后对问题的子集进行编码,可能只有一个列表用于过滤。这样你就可以自己解决问题,或者提出一个可以用几段话回答的问题。