本文整理匯總了Java中org.springframework.data.domain.PageImpl類的典型用法代碼示例。如果您正苦於以下問題:Java PageImpl類的具體用法?Java PageImpl怎麽用?Java PageImpl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PageImpl類屬於org.springframework.data.domain包,在下文中一共展示了PageImpl類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: queryPage
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Override
public Page<User> queryPage(SysRole role, UserQueryRequest queryRequest) {
int start = queryRequest.getStart();
int limit = queryRequest.getLimit();
Query query = new Query();
query.addCriteria(Criteria.where("roles").in(role));
if (!StringUtils.isEmpty(queryRequest.getUsername())) {
query.addCriteria(Criteria.where("username").regex(queryRequest.getUsername()));
}
query.addCriteria(Criteria.where("deleted").ne(true));
PageRequest pageable = new PageRequest(start, limit, new Sort(Sort.Direction.DESC, "username"));
query.with(pageable);
long count = mongoTemplate.count(query, User.class);
List<User> list = mongoTemplate.find(query, User.class);
return new PageImpl<>(list, pageable, count);
}
示例2: search
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Override
public Page search(QueryCriteria criteria, Pageable pageable) {
CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();
CriteriaQuery<Long> countCriteria = builder.createQuery(Long.class);
Root<T> countRoot = countCriteria.from(this.domainClass);
long total = this.entityManager.createQuery(
countCriteria.select(builder.count(countRoot))
.where(toPredicates(criteria, countRoot, builder))
).getSingleResult();
CriteriaQuery<T> pageCriteria = builder.createQuery(this.domainClass);
Root<T> pageRoot = pageCriteria.from(this.domainClass);
List<T> list = this.entityManager.createQuery(
pageCriteria.select(pageRoot)
.where(toPredicates(criteria, pageRoot, builder))
.orderBy(toOrders(pageable.getSort(), pageRoot, builder))
).setFirstResult(pageable.getOffset())
.setMaxResults(pageable.getPageSize())
.getResultList();
return new PageImpl<>(new ArrayList<>(list), pageable, total);
}
示例3: findAllNotSecureByCompany
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void findAllNotSecureByCompany() {
final Map<String, UserOrg> users = new HashMap<>();
final UserOrg user1 = newUser();
users.put("wuser", user1);
final UserOrg user2 = new UserOrg();
user2.setCompany("ing");
user2.setGroups(Collections.singletonList("any"));
users.put("user2", user2);
final GroupOrg groupOrg1 = new GroupOrg("cn=DIG,ou=fonction,ou=groups,dc=sample,dc=com", "DIG", Collections.singleton("wuser"));
final Map<String, GroupOrg> groupsMap = new HashMap<>();
groupsMap.put("dig", groupOrg1);
resource.groupResource = Mockito.mock(GroupResource.class);
final CompanyOrg company = new CompanyOrg("ou=ing,ou=france,ou=people,dc=sample,dc=com", "ing");
Mockito.when(companyRepository.findByIdExpected(DEFAULT_USER, "ing")).thenReturn(company);
groupFindById(DEFAULT_USER, "dig", groupOrg1);
Mockito.when(userRepository.findAll(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(new PageImpl<>(new ArrayList<>(users.values())));
Mockito.when(resource.groupResource.getContainers()).thenReturn(new HashSet<>(groupsMap.values()));
Mockito.when(resource.groupResource.getContainersForWrite()).thenReturn(new HashSet<>(groupsMap.values()));
final List<UserOrg> data = resource.findAllNotSecure("ing", null);
// Check the users
checkUser(data.get(0));
}
示例4: generatePaginationHttpHeadersTest
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void generatePaginationHttpHeadersTest() {
String baseUrl = "/api/_search/example";
List<String> content = new ArrayList<>();
Page<String> page = new PageImpl<>(content,new PageRequest(6, 50),400L);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, baseUrl);
List<String> strHeaders = headers.get(HttpHeaders.LINK);
assertNotNull(strHeaders);
assertTrue(strHeaders.size() == 1);
String headerData = strHeaders.get(0);
assertTrue(headerData.split(",").length == 4);
String expectedData = "</api/_search/example?page=7&size=50>; rel=\"next\","
+ "</api/_search/example?page=5&size=50>; rel=\"prev\","
+ "</api/_search/example?page=7&size=50>; rel=\"last\","
+ "</api/_search/example?page=0&size=50>; rel=\"first\"";
assertEquals(expectedData, headerData);
List<String> xTotalCountHeaders = headers.get("X-Total-Count");
assertTrue(xTotalCountHeaders.size() == 1);
assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));
}
示例5: testFindUsersByUsernameStartingWith
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void testFindUsersByUsernameStartingWith() throws Exception {
final UserEntity user = new UserEntity()
.setId("user123")
.setEmail("[email protected]");
final Page<UserEntity> users = new PageImpl<>(Arrays.asList(user));
when(userAdminService.findUsersByUsernameStartingWith(eq("user123"), any())).thenReturn(users);
ResultActions resultActions = mockMvc.perform(get("/api/users?username=user123")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("user-read-username-startingwith"));
MockHttpServletResponse response = resultActions
.andReturn()
.getResponse();
assertThat(response.getContentAsByteArray())
.isEqualTo(objectMapper.writeValueAsBytes(
users.map(u -> UserRestData.builder().fromUserEntity(u).build())));
verify(userAdminService).findUsersByUsernameStartingWith(eq("user123"), any());
}
示例6: testFindClients
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
@WithMockUser("user123")
public void testFindClients() throws Exception {
final OAuth2ClientEntity client = new OAuth2ClientEntity()
.setId("client123")
.setName("client")
.setDescription("description")
.setClientSecret("123456secret")
.setSecretRequired(true)
.setAutoApprove(false)
.setAuthorizedGrantTypes(new HashSet<>(Arrays.asList(AUTHORIZATION_CODE, IMPLICIT)));
Page<OAuth2ClientEntity> clients = new PageImpl<>(Arrays.asList(client));
when(oAuth2ClientService.findClients(anyString(), any())).thenReturn(clients);
MockHttpServletRequestBuilder request = get("/api/clients")
.contentType(MediaType.APPLICATION_JSON);
MockHttpServletResponse response = mockMvc.perform(request)
.andExpect(status().isOk())
.andDo(document("client-read-all"))
.andReturn()
.getResponse();
assertThat(response.getContentAsByteArray())
.isEqualTo(objectMapper.writeValueAsBytes(
clients.map(c -> OAuth2ClientRestData.builder().fromOAuth2ClientEntity(c).build())));
verify(oAuth2ClientService).findClients(anyString(), any());
}
示例7: testFindPrivileges
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void testFindPrivileges() throws Exception {
PrivilegeEntity dbResult = new PrivilegeEntity()
.setId("123")
.setName("12345")
.setDescription("Description 12345");
Page<PrivilegeEntity> pageResponseBody = new PageImpl<>(Arrays.asList(dbResult));
Page<PrivilegeRestData> expectedResponseBody = new PageImpl<>(Arrays.asList(PrivilegeRestData.builder()
.fromPrivilegeEntity(dbResult).build()));
when(privilegeService.findPrivileges(anyString(), any())).thenReturn(pageResponseBody);
ResultActions resultActions = mockMvc.perform(get("/api/privileges").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("privilege-read-all"));
MockHttpServletResponse response = resultActions
.andReturn()
.getResponse();
verify(privilegeService).findPrivileges(anyString(), any());
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(expectedResponseBody));
}
示例8: testGetInstancesCountByNamespace
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void testGetInstancesCountByNamespace() throws Exception {
String someAppId = "someAppId";
String someClusterName = "someClusterName";
String someNamespaceName = "someNamespaceName";
Page<Instance> instances = new PageImpl<>(Collections.emptyList(), pageable, 2);
when(instanceService.findInstancesByNamespace(eq(someAppId), eq(someClusterName),
eq(someNamespaceName), any(Pageable.class))).thenReturn(instances);
long result = instanceConfigController.getInstancesCountByNamespace(someAppId,
someClusterName, someNamespaceName);
assertEquals(2, result);
}
示例9: fromPage
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void fromPage(){
// Given: A Page
Page<String> myPage = new PageImpl<>(
Arrays.asList("a", "b", "c"),
PageRequest.of(1, 3), // page == 1 => 2nd page (zero index)
9
);
ContinuableListing<String> listing = ContinuationSupport.fromPage(myPage);
Assert.assertEquals(3, listing.getChunkSize());
Assert.assertEquals(3, listing.getContent().size());
Assert.assertEquals(true, listing.hasMore());
Assert.assertEquals("1-3", listing.getContinuationToken());
Assert.assertEquals("2-3", listing.getNextContinuationToken());
}
示例10: commaTest
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void commaTest() {
String baseUrl = "/api/_search/example";
List<String> content = new ArrayList<>();
Page<String> page = new PageImpl<>(content);
String query = "Test1, test2";
HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
List<String> strHeaders = headers.get(HttpHeaders.LINK);
assertNotNull(strHeaders);
assertTrue(strHeaders.size() == 1);
String headerData = strHeaders.get(0);
assertTrue(headerData.split(",").length == 2);
String expectedData = "</api/_search/example?page=0&size=0&query=Test1%2C+test2>; rel=\"last\","
+ "</api/_search/example?page=0&size=0&query=Test1%2C+test2>; rel=\"first\"";
assertEquals(expectedData, headerData);
List<String> xTotalCountHeaders = headers.get("X-Total-Count");
assertTrue(xTotalCountHeaders.size() == 1);
assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(0L));
}
示例11: greaterSemicolonTest
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void greaterSemicolonTest() {
String baseUrl = "/api/_search/example";
List<String> content = new ArrayList<>();
Page<String> page = new PageImpl<>(content);
String query = "Test>;test";
HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
List<String> strHeaders = headers.get(HttpHeaders.LINK);
assertNotNull(strHeaders);
assertTrue(strHeaders.size() == 1);
String headerData = strHeaders.get(0);
assertTrue(headerData.split(",").length == 2);
String[] linksData = headerData.split(",");
assertTrue(linksData.length == 2);
assertTrue(linksData[0].split(">;").length == 2);
assertTrue(linksData[1].split(">;").length == 2);
String expectedData = "</api/_search/example?page=0&size=0&query=Test%3E%3Btest>; rel=\"last\","
+ "</api/_search/example?page=0&size=0&query=Test%3E%3Btest>; rel=\"first\"";
assertEquals(expectedData, headerData);
List<String> xTotalCountHeaders = headers.get("X-Total-Count");
assertTrue(xTotalCountHeaders.size() == 1);
assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(0L));
}
示例12: listHot
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
/**
* Retrieves hot medium elements from the cache and retrieves the object information from the database
*
* @param pageable pagination settings
* @return list of medium elements
*/
@ApiOperation("Retrieves all Media elements by how \"hot\" they are")
@RequestMapping(value = "/Hot", method = RequestMethod.GET)
Page<Medium> listHot(final Pageable pageable) {
final int page = pageable.getPageNumber();
final int count = pageable.getPageSize();
final RScoredSortedSet<String> set = redissonClient.getScoredSortedSet("HotMediaByScore");
if (set.size() == 0) {
retrieveHotToCache();
}
final Collection<ScoredEntry<String>> mediaCollection = set.entryRange(page * count, ((page + 1) * count) - 1);
final List<Medium> mediaList = mediaCollection.stream()
.map(entry -> mediumService.findOne(entry.getValue()))
.filter(Optional::isPresent)
.map(Optional::get)
.filter(AuditedEntity::getActive)
.collect(Collectors.toList());
return new PageImpl<>(mediaList, pageable, set.size());
}
示例13: findAllNotSecureByGroup
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@Test
public void findAllNotSecureByGroup() {
final Map<String, UserOrg> users = new HashMap<>();
final UserOrg user1 = newUser();
users.put("wuser", user1);
final UserOrg user2 = new UserOrg();
user2.setCompany("ing");
user2.setGroups(Collections.singletonList("any"));
users.put("user2", user2);
final GroupOrg groupOrg1 = new GroupOrg("cn=DIG,ou=fonction,ou=groups,dc=sample,dc=com", "DIG", Collections.singleton("wuser"));
final Map<String, GroupOrg> groupsMap = new HashMap<>();
groupsMap.put("dig", groupOrg1);
resource.groupResource = Mockito.mock(GroupResource.class);
final CompanyOrg company = new CompanyOrg("ou=ing,ou=france,ou=people,dc=sample,dc=com", "ing");
Mockito.when(companyRepository.findByIdExpected(DEFAULT_USER, "ing")).thenReturn(company);
groupFindById(DEFAULT_USER, "dig", groupOrg1);
Mockito.when(userRepository.findAll(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(new PageImpl<>(new ArrayList<>(users.values())));
Mockito.when(resource.groupResource.getContainers()).thenReturn(new HashSet<>(groupsMap.values()));
Mockito.when(resource.groupResource.getContainersForWrite()).thenReturn(new HashSet<>(groupsMap.values()));
final List<UserOrg> data = resource.findAllNotSecure(null, "dig");
// Check the users
checkUser(data.get(0));
}
示例14: centerfans
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@RequestMapping("/center/fans")
@Menu(type = "apps" , subtype = "user" , name="fans" , access = false)
public ModelAndView centerfans(HttpServletRequest request , HttpServletResponse response, @Valid String orgi, @Valid String q) {
ModelAndView view = request(super.createAppsTempletResponse("/apps/user/centerfans")) ;
String userid = super.getUser(request).getId() ;
Pageable page = new PageRequest(super.getP(request), super.getPs(request), new Sort(Direction.DESC, "createtime")) ;
Page<Fans> fansList = fansRes.findByUser(userid, page) ;
List<String> userids = new ArrayList<String>();
for(Fans fan : fansList){
userids.add(fan.getCreater()) ;
}
if(userids.size()>0){
view.addObject("fansList",new PageImpl<User>(userRes.findAll(userids), page, fansList.getTotalElements()) ) ;
}
return view;
}
示例15: centerfollows
import org.springframework.data.domain.PageImpl; //導入依賴的package包/類
@RequestMapping("/center/follows")
@Menu(type = "apps" , subtype = "user" , name="follows" , access = false)
public ModelAndView centerfollows(HttpServletRequest request , HttpServletResponse response, @Valid String orgi, @Valid String q) {
ModelAndView view = request(super.createAppsTempletResponse("/apps/user/centerfollows")) ;
String userid = super.getUser(request).getId() ;
Pageable page = new PageRequest(super.getP(request), super.getPs(request), new Sort(Direction.DESC, "createtime")) ;
Page<Fans> fansList = fansRes.findByCreater(userid, page) ;
List<String> userids = new ArrayList<String>();
for(Fans fan : fansList){
userids.add(fan.getUser()) ;
}
if(userids.size()>0){
view.addObject("fansList",new PageImpl<User>(userRes.findAll(userids), page, fansList.getTotalElements()) ) ;
}
return view;
}