Sar*_* I. 4 java mysql hibernate jdbc spring-data-jpa
我在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);
Run Code Online (Sandbox Code Playgroud)
我想用限制和大小检索,就像这样
SELECT * FROM tblDirectiveParagraph where intDirectiveID = 1 limit 10,10;
Run Code Online (Sandbox Code Playgroud)
如何为上面的@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);
Run Code Online (Sandbox Code Playgroud)
这是一个示例方法调用:
public void someMethod(){
PageRequest pageR = new PageRequest(10,10);
Page<DirectiveParagraph> result = directiveParagraphRepository.getByName("txtDirCode",pageR);
List<DirectiveParagraph> resultList = result.getContent();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3154 次 |
| 最近记录: |