Modify rule S7186: update description to focus more explicitly on the Data Repository (#4787)

This commit is contained in:
erwan-serandour 2025-03-14 16:30:40 +01:00 committed by GitHub
parent 85743bd38f
commit 5b2ef9ae42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@
Spring Data Repository supports paging for queries, allowing you to return results in small, manageable chunks rather than retrieving an entire large result set.
The conventional approach to paginating data in Spring is to use the `Pageable` interface to control pagination and to store the query results into a `Page` or `Slice`.
If a query method in a `Repository` returns a `Page` or `Slice` without taking a `Pageable` as an input, it raises a runtime exception.
If a query declaration in a `Spring Data Repository` returns a `Page` or `Slice` without taking a `Pageable` as an input, it raises a runtime exception.
This rule raises an issue on queries in a `Repository` that return a `Page` or `Slice` without taking a `Pageable` as an input.
@ -17,8 +17,8 @@ Ensure that query methods returning a `Page` or `Slice` include a `Pageable` par
[source,java,diff-id=1,diff-type=noncompliant]
----
public Page<Item> findItems() { //non compliant, no Pageable parameter
// query
interface ItemRepository extends JpaRepository<Item, Long> {
Page<Item> findItems(); //non compliant, no Pageable parameter
}
----
@ -26,8 +26,8 @@ public Page<Item> findItems() { //non compliant, no Pageable parameter
[source,java,diff-id=1,diff-type=compliant]
----
public Page<Item> findItems(Pageable pageable) {
// query
interface ItemRepository extends JpaRepository<Item, Long> {
Page<Item> findItems(Pageable pageable);
}
----