Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
使用spring数据jpa@query注释查找最大查询结果_Jpa_Spring Data Jpa - Fatal编程技术网

使用spring数据jpa@query注释查找最大查询结果

使用spring数据jpa@query注释查找最大查询结果,jpa,spring-data-jpa,Jpa,Spring Data Jpa,可以使用.setMaxResults(1).getResultList()和@query限制查询结果-类似于: @Query("SELECT l FROM LocationLog l WHERE l.visit = :visit ORDER BY l.eventTime").setMaxResults(1).getResultList() public LocationLog findLast(@Param("visit") Visit visit); 此代码不正确,因为setMaxResul

可以使用.setMaxResults(1).getResultList()和@query限制查询结果-类似于:

@Query("SELECT l FROM LocationLog l WHERE l.visit = :visit ORDER BY l.eventTime").setMaxResults(1).getResultList()
public LocationLog findLast(@Param("visit") Visit visit);

此代码不正确,因为setMaxResults等不在@Query?l

中。您不能在
@Query
注释中设置分页选项,但可以通过其他方式进行设置。您可以将方法声明更改为

public LocationLog find(@Param("visit") Visit visit, Pageable pageable);
然后,您将能够向查询调用传递其他参数:

Pageable firstFive = new PageRequest(0, 5);
LocationLog locLog = locationLogDao.find(visit, firstFive);
还可以选择了解查询结果的当前上下文,您可以使用
Page
接口将方法返回类型更改为
Page
。你可以找到所有必要的信息