I found that if you filter by conditions, there will be problems,below is my code

UserVo userVo=userVoCPage.getContent();
Page<UserTEntity> userTEntityPage=userRepository.findAll(new Specification<UserTEntity>() {
    @Override
    public Predicate toPredicate(Root<UserTEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
        List<Predicate> predicateList = new ArrayList<>();
        if (StringUtils.isNotBlank(userVo.getUserName())) {
            predicateList.add(criteriaBuilder.equal(root.get("userName"), userVo.getUserName()));
        }
        return criteriaBuilder.and(predicateList.toArray(new Predicate[predicateList.size()]));
    }
}, PageRequest.of(1,5));

Please see my debug,if this data is not in the page range, it will not be returned,this is not what i want

I need him to return,startPage update firstPage

微信图片_20200714174222

below is my solution I think this is a bug Mybatis paging plugin does not have this problem

@Override
public Page<T> findAllC(Specification<T> spec, Pageable pageable) {
    TypedQuery<T> query = getQuery(spec, pageable);

    long total = executeCountQuery(getMyCountQuery(spec,getDomainClass()));

    if (pageable.isPaged()) {
        if(total<=pageable.getOffset() && pageable.getPageNumber()>0){
            pageable= PageRequest.of(0,pageable.getPageSize());
        }
        query.setFirstResult((int) pageable.getOffset());
        query.setMaxResults(pageable.getPageSize());
    }

    return PageableExecutionUtils.getPage(query.getResultList(), pageable,
                () -> total);
}

help me,thanks.

Comment From: wilkinsona

The paging and specification functionality is provided by Spring Data JPA which is managed as a seperate project. Please see the Getting Help section of their README to learn how to get some help with Spring Data JPA.