Skip to content

Commit 7aa1a7e

Browse files
committed
Part 12: Add FourthUserRepository.java
1 parent 7178ec2 commit 7aa1a7e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package spring.oldboy.database.repository.user_repository;
2+
3+
/* Part 10: Lesson 53 - Интерфейсы Slice, Pageable */
4+
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.domain.Slice;
8+
import org.springframework.data.jpa.repository.JpaRepository;
9+
import org.springframework.data.jpa.repository.Query;
10+
import org.springframework.stereotype.Repository;
11+
import spring.oldboy.database.entity.User;
12+
13+
/* Изменим наш класс на интерфейс и расширим JpaRepository */
14+
@Repository
15+
public interface FourthUserRepository extends JpaRepository<User, Long> {
16+
17+
/*
18+
Part 10: Lesson 53:
19+
В DOC/SpringDataJPATutorial/5_IntroductionQueryMethods.txt мы уже выяснили,
20+
что можем возвращать Collection, Stream, так же Spring позволяет возвращать:
21+
Streamable, Slice, Page.
22+
23+
В данном методе мы наш Lise<User>, просто поменяем на Slice:
24+
*/
25+
Slice<User> findAllUserBy(Pageable pageable);
26+
/*
27+
Part 10: Lesson 53:
28+
В DOC/SpringDataJPATutorial/5_IntroductionQueryMethods.txt мы уже выяснили,
29+
что можем возвращать Collection, Stream, так же Spring позволяет возвращать:
30+
Streamable, Slice, Page.
31+
32+
Вернем теперь Page<User>:
33+
*/
34+
Page<User> findAllUserPagesBy(Pageable pageable);
35+
36+
/* При помощи аннотации @Query мы можем влиять на count */
37+
@Query(value = "select u from User u",
38+
countQuery = "select count(distinct u.firstname) from User u")
39+
Page<User> findAllUserPagesWithCountBy(Pageable pageable);
40+
41+
}

0 commit comments

Comments
 (0)