sql >> Databasteknik >  >> RDS >> Mysql

Java Spring JPA Paginering Fungerar inte om mer än en sida

Efter att ha spenderat lite tid hittade jag svaret

Jag missade räknefrågan. Efter att ha lagt till räknefrågan fungerade paginering som charm :)

@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 raderingsoperation

  2. Hur kan jag skriva en användardefinierad funktion i MySQL så att när jag tar bort en rad från en tabell, så raderas den specifika raden från en annan tabell?

  3. MySQL användarrättigheter på delade servrar

  4. Fråga en MySQL db med java