PagingAndSortingRepositoryインタフェース

2917 ワード

PagingAndSortingRepository
  • インタフェースは、ページングおよびソート機能
  • を提供する.
    Iterable findAll(Sort sort); //   
    Page findAll(Pageable pageable); //    (     ) 
    
  • 実列(このインタフェースを実現すれば直接無効になる)
  • public class SpringDataTest {
       private ApplicationContext ctx = null ;
       PersonRepsotory personRepsotory = null;
    
       {
           ctx =  new ClassPathXmlApplicationContext("applicationContext.xml");
           personRepsotory = ctx.getBean(PersonRepsotory.class);
    
     } 
    
    public void testPageingAndSortingRepsotory(){
           // pageNo   0   
           int pageNo = 3-1; //         
           int pageSize = 5;
           // Pageable        PageRequest    ,            
           //       Sort         
    
           //Order                   
           Order order1 = new Order(Direction.DESC,"id");
           Order order2 = new Order(Direction.ASC,"email");
           Sort sort = new Sort(order1,order2);
           PageRequest pageable = new PageRequest(pageNo,pageSize,sort);
          // PageRequest pageable = new PageRequest(pageNo,pageSize);
    
    
           Page page = personRepsotory.findAll(pageable);
           System.out.println("    :" + page.getTotalElements());
           System.out.println("     " + (page.getNumber()+1));
           System.out.println("   " + page.getTotalPages());
           System.out.println("     list" +page.getContent() );  
           System.out.println("        " + page.getNumberOfElements());
       }