|
| 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