Browse Source

page

master
nelson 5 years ago
parent
commit
459fbe55e3
  1. 9
      src/main/java/com/example/sbmongo/controller/UserController.java
  2. 2
      src/main/java/com/example/sbmongo/service/UserService.java
  3. 5
      src/main/java/com/example/sbmongo/service/impl/UserServiceImpl.java

9
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<User> teacherPage = userService.findByUsername("nelson", pageable1);
Page<User> page= userService.findByPage(pageable);
return page;
}
}

2
src/main/java/com/example/sbmongo/service/UserService.java

@ -14,4 +14,6 @@ public interface UserService {
List<User> finAll();
User findByUsername(String nelson);
Page<User> findByPage(Pageable pageable);
}

5
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<User> findByPage(Pageable pageable) {
return userRepository.findAll(pageable);
}
}

Loading…
Cancel
Save