I have a submission table with columns like ID
, Name
, Code
among other properties. My requirement is to search for records based on the me
You can use Pageable
in the repository method in Spring
@Repository
public interface StateRepository extends JpaRepository {
@Query("select state from State state where state.stateId.stateCode = ?1")
public State findStateByCode(String code, Pageable pageable);
}
And in the service layer, you can create the Pageable
object:
@Autowire
StateRepository stateRepository;
public State findStateServiceByCode(String code, int page, int size) {
Pageable pageable = new PageRequest(page, size);
Page statePage = stateRepository.findStateByCode(code, pageable);
return statePage.getContent();
}