我们可以从字符串中通过QUERY附加Query的值吗? 如果没有,还有其他选择吗?
注意:需要返回页面中的数据
@Query(nativeQuery = true,value =“从表实体中选择实体,其中 1 = 1“ +查询+” AND date =:date“)
页面getSearchedTable(字符串查询,@ Param(“日期”)LocalDate businessDate,可分页的可分页);
答案 0 :(得分:0)
您可以使用以下查询获取可分页的数据。谨记几点
@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);
但是,如果必须强制使用nativeQuery,则可以选择以下任意查询。
1。首选
@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。第二种选择
@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);