问题标签 [pageable]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1026 浏览

pagination - 如何使用带有 Pageable 的 Spring Data JPA 分页来更改数据?

我指的是这个博客中的例子 - https://www.logicbig.com/tutorials/spring-framework/spring-data/pagination-returning-page.html

在这里,在阅读了第一页之后,我正在修改页面中返回的所有条目的部门。因此,当获取第二页时,总编号。页的变化。这导致只有部分数据被更改。例如,代码检索第 1 页(共 5 页),然后检索第 2 页(共 4 页)和第 3 页(共 3 页)并结束。有没有办法在每次迭代时刷新页码以及总页数或更好的方法?

0 投票
1 回答
259 浏览

mysql - 如何使用 Spring-data-jpa 确定记录的页码?

我想返回某条记录所在页面的页码。我使用条件查询返回所有的分页结果,所以我无法根据记录的id确定它所在的页面。我怎么解决这个问题?

我在网上找了很久。但是没有用。请帮助或尝试提供一些想法如何实现这一目标。

我的临时解决方案是查询每个页面的记录,直到它包含我需要的记录,但是这样做会导致查询变慢。

ps:我使用的是 MySQL 数据库。

0 投票
0 回答
113 浏览

jpa - 如何解决这个简单但未解决的 JPA 分页问题?

我正在尝试在我的 spring boot 应用程序中使用 native query 和 pagination 进行查询。

抛出的异常就像Caused by: org.postgresql.util.PSQLException: ERROR: column pg.id does not exist Position: XX.

更新 :

让我们拿一个用户类样本:

0 投票
2 回答
129 浏览

java - 我使用@Query 和 Pageable 有错误:只有在通过引用列名的表达式进行排序时才允许使用变量

我试图查询:

我的页面请求:

运行时的休眠查询

**> 休眠:

错误:2020 年 5 月 17 日下午 12:41:29 org.apache.catalina.core.StandardWrapperValve 调用严重:servlet [dispatcher] 的 Servlet.service() 在路径 [/CarPark] 的上下文中抛出异常 [请求处理失败;嵌套异常是 org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause com.microsoft.sqlserver.jdbc.SQLServerException: ORDER BY number 1 标识的 SELECT 项包含一个变量作为标识列的表达式的一部分位置。只有在通过引用列名的表达式进行排序时才允许使用变量。 在 com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254) 在 com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1608) 在 com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement (SQLServerPreparedStatement.java:578) 在 com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:508) 在 com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240) 在 com。 microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869) 在 com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:243) 在 com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement. java:218) 在 com.microsoft。org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60) 中的 org.hibernate.loader.Loader.getResultSet(Loader.java: 中的 sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:434) 2171) 在 org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1934) 在 org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1896) 在 org.hibernate.loader.Loader.doQuery(Loader.java :936) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:339) org.hibernate.loader.Loader.doList(Loader.java:2693) org.hibernate.loader.Loader.doList(Loader. java:2676) 在 org.hibernate.loader.custom.CustomLoader 的 org.hibernate.loader.Loader.list(Loader.java:2505) 的 org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2510)。list(CustomLoader.java:338) at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2262) at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1069) at org.hibernate.query.internal .NativeQueryImpl.doList(NativeQueryImpl.java:173) 在 org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529) 在 org.hibernate.query.Query.getResultList(Query.java:165) 在太阳。 reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(方法.java:498) ....java:2262) 在 org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:173) 在 org.hibernate.query.internal.AbstractProducedQuery 的 org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1069) .list(AbstractProducedQuery.java:1529) 在 org.hibernate.query.Query.getResultList(Query.java:165) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) ....java:2262) 在 org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:173) 在 org.hibernate.query.internal.AbstractProducedQuery 的 org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1069) .list(AbstractProducedQuery.java:1529) 在 org.hibernate.query.Query.getResultList(Query.java:165) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java :62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) ....java:173) 在 org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529) 在 org.hibernate.query.Query.getResultList(Query.java:165) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native方法)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 。 ...java:173) 在 org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1529) 在 org.hibernate.query.Query.getResultList(Query.java:165) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native方法)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 。 ...在 java.lang.reflect.Method.invoke(Method.java:498) 处调用(DelegatingMethodAccessorImpl.java:43) ....在 java.lang.reflect.Method.invoke(Method.java:498) 处调用(DelegatingMethodAccessorImpl.java:43) ....

**我的数据库**

请帮我!谢谢

0 投票
1 回答
353 浏览

spring-data - 如何在spring boot中使用Pageable接口从http url中删除/处理不相关或错误的排序参数?

如何在spring boot中使用Pageable接口从http url中删除/处理不相关或错误的排序参数?

例如,我有一个类似 http://localhost:8080/all?sort=firstName,asc&sort=nosuchfield,asc的查询

如何处理或删除不相关的字段“nosuchfield”?

另外,如何限制 URL 中的排序参数?

0 投票
2 回答
686 浏览

spring - 在spring boot中使用pageable获取和删除对象

我有一个名为 getAllEmployees() 的方法,它返回一个可分页的。

假设页面大小为 1 并从第 0 页开始

可分页可分页 = PageRequest.of(0, 1);

  • 在这种情况下,所有员工都不会被删除,只有符合条件的员工才会被删除

因为页面大小为 1

假设共有 6 名员工

当 1 被删除时,分页将像

但是当我们使用 page.nextPageable() 时,下一个将像 (1,1)

所以在下一次 fetch 时,它将选择 emp 3,而 emp 2 将被错过

0 投票
0 回答
495 浏览

javascript - 如何在向 Spring API 发送查询方向的 javascript 中格式化 Pageable json 对象

我想作为 Pageable 对象的一部分发送查询“ ASC ”或“ DESC ”的方向/顺序。所以我的问题是,即使我将方向设置为 pageable 的值并且 API URL 请求中包含此信息,Spring 后端也无法正确解析 Pageble 对象并且它始终将ASC显示为方向(我认为这可能是默认状态)。

这是我在 Angular 控制器中的过滤方法

这是我在这个实体的服务中的 API 调用

这是它创建的请求

在此处输入图像描述

这是 IDE 上的调试显示

在此处输入图像描述

0 投票
3 回答
3641 浏览

spring-boot - 春季可分页以在列表上分页 is not working

I have a list of object which contain 10000 records i am trying to split that records in each of 10,

But somehow it is not working.. can someone have a look

@Query("select a.appli

I have a list of object which contain 10000 records i am trying to split that records in each of 10,

But somehow it is not working.. can someone have a look

where i am going wrong in this ? if i am trying to add pagable object to query and run the code i will get the following error:

Cannot create TypedQuery for query with more than one return using requested result type [java.lang.Long]; nested exception is java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return using requested result type [java.lang.Long]


Page just represents one page of data . So page.getContent() only return all data in one page which is specified through constructor when you create this page instance . It has nothing to do with splitting the data in a page.

If you want to split a list , use Lists from Guava is the simplest way to go :

If you want to do pagination which split all the data stored in the database into different smaller pages , split it at the database level rather than getting the whole list to the memory to split which will be very inefficient when the entire list is large. See this for how to split it at the database level by declaring Pageable in the query method.

0 投票
1 回答
525 浏览

java - 使用 Hibernate Search 查询并获取所有项目而无需分页

我在我的 Spring Boot 项目中使用 Hibernate Search。大多数情况下,它是满足我需求的完美解决方案,除非有一种情况是我必须通过全文搜索查询选择所有项目。

使用 Hibernate Search 时是否有机会避免 Hibernate Search / Lucene 分页?类似的东西Pageable.unpaged()?我不想将页面大小设置为,Integer.MAX_VALUE因为它是一种黑客行为。但如果没有更好的解决方案,我将不得不那样使用它。

0 投票
1 回答
1156 浏览

spring-data-jpa - 我们可以在 JPA 查询中同时使用 HINT_FETCH_SIZE 和 Pageable

我的JpaRepository. 我的Pageable大小为 1000 条记录,但HINT_FETCH_SIZE为 50。这是否意味着填充Page1000 条记录,此查询被称为 20 次(20 x fetch size 50)?我的理解正确吗?HINT_FETCH_SIZE如果我们需要Pageable1000 条记录,理想的情况是什么?