Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
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 ;
}
}