JPA 分页查询Pageable

 
  
service层:Service类
 
  
List getAllUser(int page , int pagesize);

DAO层:UserRepository类

@Component
public interface UserRepository extends PagingAndSortingRepository {

    Page findAll(Pageable pageable);}


serviceImpl层:ServiceImp类:


@Autowired

private UserRepository userRepository


public List<Page> getAllUser(int page,int pagesize){

PageRequest request =new PageRequest (page-1,pagesize,null);

Page userList = userRepository.findAll(request);

List> list = null;

list.add(userList);

return list;

}


Controller层:UserController类:



@Autowired

private Service s;
在方法里获取数据:
s.getAllUser(page,pagesize);

@Autowired


你可能感兴趣的:(Java)