Custom criteria query test

1      // custom query test conditions 
2      @Test
 . 3      public  void testFindAllByExample () {
 . 4          // paging parameters 
. 5          int Page = 0; // starting from 0 
. 6          int size = 10 ;
 . 7          / * 
. 8          // paging parameters
 . 9          IF (Page <= 0) {
 10              Page =. 1;
 . 11          }
 12 is          IF (size <= 0) {
 13 is              size = 10;
 14          }
 15          // constructor method of paging query
 16          Page Page = -. 1;
 . 17         * / 
18          the Pageable the Pageable = PageRequest.of (Page, size);
 19  
20          // condition value of the object 
21          CmsPage cmsPage = new new CmsPage ();
 22          // To query 5a751fab6abb5044e0d19ea1 site page
 23  //         cmsPage.setSiteId ( "5a751fab6abb5044e0d19ea1" );
 24          // set the template id conditions
 25  //         cmsPage.setTemplateId ( "5ad9a24d68db5239b8fef199");
 26          // set PageAlias 
27          cmsPage.setPageAliase ( "carousel" );
 28          // condition matcher 
29          / *ExampleMatcher exampleMatcher = ExampleMatcher.matching();
30         exampleMatcher = exampleMatcher.withMatcher("pageAliase", ExampleMatcher.GenericPropertyMatchers.contains());
31 //        exampleMatcher = exampleMatcher.withMatcher("templateId", ExampleMatcher.GenericPropertyMatchers.contains());
32         */
33         ExampleMatcher exampleMatcher = ExampleMatcher.matching()
34                 .withMatcher("pageAliase", ExampleMatcher.GenericPropertyMatchers.contains())
35                 .withMatcher("templateId", ExampleMatcher.GenericPropertyMatchers.contains());
36                                                      //ExampleMatcher.GenericPropertyMatchers.contains () contains the keyword (fuzzy match)
 37 [                                                       // ExampleMatcher.GenericPropertyMatchers.startsWith () Match prefix
 38 is                                                       // ExampleMatcher.GenericPropertyMatchers.exact () process state exact match (default)
 39  
40          // defined condition objects Example 
41 is          Example <CmsPage> = Example Example.of (cmsPage, exampleMatcher);
 42 is          Page <CmsPage> All = ; cmsPageRepository.findAll (Example, Pageable)
 43 is          list <CmsPage> content1 all.getContent = (); // data list 
44 is          Long totalElements all.getTotalElements = (); // total number of data records 
45  
46 is         List<CmsPage> content = all.getContent();
47         System.out.println(content);
48     }

Guess you like

Origin www.cnblogs.com/foshuo-cv/p/12036795.html
Recommended