You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
package com.example.sbmongo.controller;
|
|
|
|
import com.example.sbmongo.model.User;
|
|
import com.example.sbmongo.service.UserService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
@RestController
|
|
public class UserController {
|
|
|
|
@Autowired
|
|
private UserService userService;
|
|
|
|
@GetMapping("save")
|
|
public User save() {
|
|
User user = new User();
|
|
user.setAge(12);
|
|
user.setUsername(UUID.randomUUID().toString());
|
|
return userService.save(user);
|
|
}
|
|
|
|
|
|
@GetMapping("list")
|
|
public Object list() {
|
|
Pageable pageable1 = PageRequest.of(1, 3);
|
|
//获取分页数据,每页3条数,取第1页的数据,
|
|
// Page<User> teacherPage = userService.findByUsername("nelson", pageable1);
|
|
List<User> list = userService.finAll();
|
|
return list;
|
|
}
|
|
|
|
|
|
@GetMapping("user")
|
|
public User username() {
|
|
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;
|
|
}
|
|
}
|
|
|