我在Java Hibernate中有这个
@Query("SELECT dirPar FROM DirectiveParagraph dirPar, Directive dir "
+ "WHERE dirPar.directive = dir "
+ "AND dir.txtDirCode = :txtDirCode ");
List<DirectiveParagraph> getByName(@Param("txtDirCode") String name, @Param("page") int page ,@Param("size") int size);
我想以相同的方式使用限制和大小进行检索
SELECT * FROM tblDirectiveParagraph where intDirectiveID = 1 limit 10,10;
如何在上述@Query注释上方添加限制
最佳答案
您可以尝试在您的getByName方法中添加Pageable参数
@Query("SELECT dirPar FROM DirectiveParagraph dirPar, Directive dir "
+ "WHERE dirPar.directive = dir "
+ "AND dir.txtDirCode = :txtDirCode ");
Page<DirectiveParagraph> getByName(@Param("txtDirCode") String name, Pageable page);
这是一个示例方法调用:
public void someMethod(){
PageRequest pageR = new PageRequest(10,10);
Page<DirectiveParagraph> result = directiveParagraphRepository.getByName("txtDirCode",pageR);
List<DirectiveParagraph> resultList = result.getContent();
}