sql >> Database teknologi >  >> RDS >> Mysql

Java Spring JPA Paginering Virker ikke, hvis mere end én side

Efter at have brugt noget tid fandt jeg svaret

Jeg gik glip af optællingsforespørgslen. Efter at have tilføjet tælleforespørgslen virkede paginering som charme :)

@Repository
public interface SmsLogRepository extends JpaRepository<SmsLog, Long> {

@Query(value = "select * from sms_log s where s.phone_number = (:ph) \n#pageable\n", countQuery = "select count(*) from sms_log s where s.phone_number = (:ph) \n#pageable\n", nativeQuery = true)
Page<SmsLog> findByPhoneNumber(@Param("ph") String phoneNumber, Pageable pageable);

@Query(value = "select * from sms_log s where s.phone_number = (:ph) AND s.message_timestamp between (:fromdate) and (:todate) \n#pageable\n",countQuery = "select count(*) from sms_log s where s.phone_number = (:ph) AND s.message_timestamp between (:fromdate) and (:todate) \n#pageable\n", nativeQuery = true)
Page<SmsLog> findByPhoneNumberAndDate(@Param("ph") String phoneNumber, @Param("fromdate") String fromDate, @Param("todate") String todate, Pageable pageable);

@Query(value = "select * from sms_log s where s.message_timestamp between (:fromdate) and (:todate) \n#pageable\n",countQuery = "select count(*) from sms_log s where s.message_timestamp between (:fromdate) and (:todate) \n#pageable\n", nativeQuery = true)
Page<SmsLog> findByDate(@Param("fromdate") String fromDate, @Param("todate") String todate, Pageable pageable);
}



  1. mysql:Få seneste samtaleposter efter bruger

  2. Hvordan søger og erstatter man alle forekomster af en streng i en database?

  3. Sådan opretter du en MySQL-installation til lokal test

  4. Hvad er MySQL JDBC-driverforbindelsesstrengen?