Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用多个“like”和Pageable创建Spring存储库选择_Java_Sql_Spring Data_H2 - Fatal编程技术网

Java 使用多个“like”和Pageable创建Spring存储库选择

Java 使用多个“like”和Pageable创建Spring存储库选择,java,sql,spring-data,h2,Java,Sql,Spring Data,H2,我正在使用H2数据库和Spring数据分页存储库。我喜欢使用分页并从html字段包含“@”或“[at]”或“at”或“mail”的数据库中选择所有文章 因此,不带分页的本机查询如下所示 SELECT * FROM article WHERE (html LIKE '%@%' or html LIKE '%(at)%' or html LIKE '%[at]%' or ...) 我试着这样解决它: Page<Article> findByHtmlContainingOrderByD

我正在使用H2数据库和Spring数据分页存储库。我喜欢使用分页并从html字段包含“@”或“[at]”或“at”或“mail”的数据库中选择所有文章

因此,不带分页的本机查询如下所示

SELECT * FROM article  WHERE (html LIKE '%@%' or html LIKE '%(at)%' or html LIKE '%[at]%' or ...)
我试着这样解决它:

Page<Article> findByHtmlContainingOrderByDateDesc(String[] string,  Pageable pageable);
但是没有/空的结果

我尝试的第二种方法是使用本机查询:

@Query(value = "SELECT * FROM article  WHERE (html LIKE '%@%' or html LIKE '%(at)%') ORDER BY DATE desc \n#pageable\n" , 
nativeQuery = true,
countQuery = "SELECT count(*) FROM article  WHERE (html LIKE '%@%' or html LIKE '%(at)%')")
Page<Article> findAll(@Param("pageable") Pageable pageable);
但我有个例外:

嵌套异常为org.hibernate.exception.sqlgrammareexception:无法准备语句]并带有根本原因


非常感谢你的帮助

对我有效的解决方案是将\n-pageable\n添加到自定义查询中。所以我最终在

@Query(value = "SELECT * FROM article  WHERE (html LIKE '%@%' or html LIKE '%(at)%') ORDER BY DATE desc \n-- #pageable\n" , nativeQuery = true,
    countQuery = "SELECT count(*) FROM article  WHERE (html LIKE '%@%' or html LIKE '%(at)%')")
Page<Article> findAll(@Param("pageable") Pageable pageable);
你们有并没有看过分页魔术的一些依赖于数据库的变化。