I'm trying toimplement a search function for my table of users. I want to make a JpaRepository method that will give me a pageable list of my users that have their emails containing a given String, how can I do that? This is whatIhave tried The repository:
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Page<User> findByEmailContaining(String email, Pageable pageable);
}
The servive:
public Page<User> findPaginatedEmail(int pageNo, int pageSize, String sortField, String sortDirection, String text) {
Sort sort = sortDirection.equalsIgnoreCase(Sort.Direction.ASC.name()) ? Sort.by(sortField).ascending() :
Sort.by(sortField).descending();
Pageable pageable = PageRequest.of(pageNo - 1, pageSize, sort);
return this.userRepository.findByEmailContaining(text, pageable);
}
Sometimes it works and populates my table and sometimes it doesn't. What is the problem? How do I implement it?
It works fine but after a time it simply breaks I dont know why, then it wont find anything