From 459fbe55e365721fa7842505160af464584b5d2f Mon Sep 17 00:00:00 2001 From: nelson Date: Sun, 18 Aug 2019 19:37:20 +0800 Subject: [PATCH] page --- .../com/example/sbmongo/controller/UserController.java | 9 +++++++++ .../java/com/example/sbmongo/service/UserService.java | 2 ++ .../example/sbmongo/service/impl/UserServiceImpl.java | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/src/main/java/com/example/sbmongo/controller/UserController.java b/src/main/java/com/example/sbmongo/controller/UserController.java index 17e9381..f9ac8c9 100644 --- a/src/main/java/com/example/sbmongo/controller/UserController.java +++ b/src/main/java/com/example/sbmongo/controller/UserController.java @@ -42,4 +42,13 @@ public class UserController { User list = userService.findByUsername("nelson"); return list; } + + @GetMapping("page") + public Object page() { + Pageable pageable = PageRequest.of(1, 3); + //获取分页数据,每页3条数,取第1页的数据, +// Page teacherPage = userService.findByUsername("nelson", pageable1); + Page page= userService.findByPage(pageable); + return page; + } } diff --git a/src/main/java/com/example/sbmongo/service/UserService.java b/src/main/java/com/example/sbmongo/service/UserService.java index f15c009..8d74947 100644 --- a/src/main/java/com/example/sbmongo/service/UserService.java +++ b/src/main/java/com/example/sbmongo/service/UserService.java @@ -14,4 +14,6 @@ public interface UserService { List finAll(); User findByUsername(String nelson); + + Page findByPage(Pageable pageable); } diff --git a/src/main/java/com/example/sbmongo/service/impl/UserServiceImpl.java b/src/main/java/com/example/sbmongo/service/impl/UserServiceImpl.java index 016aff4..5c19572 100644 --- a/src/main/java/com/example/sbmongo/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/sbmongo/service/impl/UserServiceImpl.java @@ -35,4 +35,9 @@ public class UserServiceImpl implements UserService { public User findByUsername(String username) { return userRepository.findByUsername(username); } + + @Override + public Page findByPage(Pageable pageable) { + return userRepository.findAll(pageable); + } }