you can use below query to get pageable data. Keep few points in mind
- You must give space between equal sign and parameter like (data = :date)
- No need to give nativeQuery = true, you can use entity fields
- You can not use "query" as your variable in native query in spring boot. You must pass as a parameter from service.
- Just pass your query parameter in required query like select or as per your req. with below example.
@Query(value = "select entity from table entity where 1=1 AND date = :date AND query = :query")
Page<YourTableEntity> getSearchedTable(@Param("query") String query, @Param("businessDate") LocalDate businessDate, Pageable pageable);
However, if you have to mandatory use nativeQuery, then you can choose any of the following queries.
1. First option
@Query(
value = "select entity from table entity where 1=1 AND date = :date AND query = :query ORDER BY id",
countQuery = "SELECT count(*) FROM table",
nativeQuery = true)
Page<YourTableEntity> getSearchedTable(@Param("query") String query, @Param("businessDate") LocalDate businessDate, Pageable pageable);
2. Second option
@Query(value = "select entity from table entity where 1=1 AND date = :date AND query = :query ORDER BY id \n-- #pageable\n",
countQuery = "SELECT count(*) FROM table",
nativeQuery = true)
Page<YourTableEntity> getSearchedTable(@Param("query") String query,
@Param("businessDate") LocalDate businessDate, Pageable pageable);