当模糊查询参数为10(长度大于1)时,result没有数据显示,但count是对的
当模糊查询参数为a(长度为1)时,有数据显示
相关代码:
public interface ArticleRepository extends JpaRepository<Article, Integer>, JpaSpecificationExecutor<Article> {
Page<Article> findByTitleContaining(String title, Pageable pageable);
}
@RequestMapping("getArticleData")
public PageResult<Article> findBySearchData(@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer size, @RequestParam(required = false) String search
){
System.out.println(search);
Pageable pageable=PageRequest.of(page,size);
Page<Article> all=articleRepository.findByTitleContaining(search,pageable);
long totalElements = all.getTotalElements();
List<Article> list = all.getContent();
int totalPages = all.getTotalPages();
PageResult<Article> pageResult = new PageResult<>();
pageResult.setCount(totalElements);
pageResult.setResult(list);
pageResult.setPage(totalPages);
return pageResult;
}
当没有用到分页的时候,模糊查询的结果都能正确获得
public interface ArticleRepository extends JpaRepository<Article, Integer>, JpaSpecificationExecutor<Article> {
List<Article> findByTitleLike(String title, Pageable pageable);
}