本文整理匯總了Java中org.springframework.data.domain.PageRequest類的典型用法代碼示例。如果您正苦於以下問題:Java PageRequest類的具體用法?Java PageRequest怎麽用?Java PageRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PageRequest類屬於org.springframework.data.domain包,在下文中一共展示了PageRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: queryPage
import org.springframework.data.domain.PageRequest; //導入依賴的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: getMyRepositoryPosts
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/** 자기가 진행중인 저장소의 글을 검색함.
* @param privateAndMassageTags
* @param search
* @param sort
* @param page
* @param size
* @return
*/
public List<Post> getMyRepositoryPosts(List<String> privateAndMassageTags, String search,
String sort, int page,int size) {
Criteria criteria = new Criteria();
criteria.and("tags").in(privateAndMassageTags);
if (search != null)
criteria.andOperator(new Criteria().orOperator(
Criteria.where("title").regex(search),
Criteria.where("content").regex(search)));
this.filter(criteria, sort);
Query query = new Query(criteria);
query.with(new PageRequest(page - 1, size));
this.sorting(query, sort);
return mongoTemplate.find(query, Post.class);
}
示例3: findBy
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
public PageWrapper<User> findBy(FindUserDTO dto, int page, int size) {
List<String> roleStr = null;
String usernameOrEmail;
if (dto.getRole() == null) {
if (UserUtils.isAdmin())
roleStr = Arrays.asList(RoleEnum.PROFESSOR.name(), RoleEnum.STUDENT.name());
else if (UserUtils.isProfessor())
roleStr = Arrays.asList(RoleEnum.STUDENT.name());
} else {
roleStr = Arrays.asList(dto.getRole().name());
}
usernameOrEmail = StringUtils.isEmpty(dto.getUsernameOrEmail()) ? "%%" : "%".concat(dto.getUsernameOrEmail().toLowerCase()).concat("%");
Pageable pageable = new PageRequest(page, size);
Page<User> pageInterface = userRepository.findBy(roleStr, usernameOrEmail, pageable);
return new PageWrapper(pageInterface.getContent(), pageable, pageInterface.getTotalElements());
}
示例4: createPageRequest
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/**
* Create pageable request with default sort.
*
* @param page Page.
* @param defaultSort Default sort object.
* @param caseSensitiveSortProperties List of case sensitive properties or {@link #CASE_SENSITIVE_PROPERTIES} for
* all properties to be case sensitive.
* @return Page object.
*/
public static PageRequest createPageRequest(Pageable page, Sort defaultSort,
Collection<String> caseSensitiveSortProperties) {
Sort sort = page.getSort();
sort = sort == null ? defaultSort : sort.and(defaultSort);
List<Sort.Order> ignoreCaseOrderList = Collections.emptyList();
if (sort != null) {
ignoreCaseOrderList = StreamUtils.createStreamFromIterator(sort.iterator())
.map(order -> {
if (caseSensitiveSortProperties == CASE_SENSITIVE_PROPERTIES ||
caseSensitiveSortProperties.contains(order.getProperty())) {
return order.ignoreCase();
}
return order;
})
.collect(Collectors.toList());
}
if (ignoreCaseOrderList.isEmpty()) {
return new PageRequest(page.getPageNumber(), page.getPageSize());
}
return new PageRequest(page.getPageNumber(), page.getPageSize(), new Sort(ignoreCaseOrderList));
}
示例5: saveAndBroadcast
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
public void saveAndBroadcast(InboundSmsMessage smsMessage){
log.info("Inbound message received {}", smsMessage);
inboundSmsMessageRepository.save(smsMessage);
Pageable page = (Pageable) PageRequest.of(0, 1, Direction.DESC, "date");
List<Conversation> conversations = conversationRepository.findByPhoneNumber(smsMessage.getMsisdn(), page);
if( ! conversations.isEmpty()){
Conversation conversation = conversations.get(0);
Optional<Participant> user = conversation.findParticipantByPhone(smsMessage.getMsisdn());
if(user.isPresent()){
ConversationMessage conversationMessage = createConversationMessage(smsMessage, conversation, user.get());
broadcastMessage(conversationMessage);
}else{
log.warn("No participant found associated with {} in {}", smsMessage.getMsisdn(), conversation.getId());
}
}else{
log.warn("No conversation found associated with {}", smsMessage.getMsisdn());
}
}
示例6: searchGoods
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/**
*
*
*
* @param pageNumber
* @param pageSize
* @param searchContent
* @return
*/
public List<GoodsModel> searchGoods(Integer pageNumber,
Integer pageSize,
String searchContent) {
// 分頁參數
Pageable pageable = new PageRequest(pageNumber, pageSize);
// Function Score Query
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("goodsName", searchContent)),ScoreFunctionBuilders.weightFactorFunction(1000))
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("description", searchContent)),ScoreFunctionBuilders.weightFactorFunction(1000));
// 創建搜索 DSL 查詢
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withPageable(pageable)
.withQuery(functionScoreQueryBuilder).build();
logger.info("\n searchGoods(): searchContent [" + searchContent + "] \n DSL = \n " + searchQuery.getQuery().toString());
Page<GoodsModel> searchPageResults = goodsESDocRepository.search(searchQuery);
return searchPageResults.getContent();
}
示例7: getPostsAsAdmin
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/** 관리자가 글을 불러올 때
* @param tags
* @param search
* @param writer
* @param sort
* @param page
* @param size
* @return
*/
public List<Post> getPostsAsAdmin(List<String> tags, String search, Weaver writer, String sort,
int page, int size) {
Criteria criteria = new Criteria();
if (search != null)
criteria.orOperator(new Criteria("title").regex(search),
new Criteria("content").regex(search));
if (tags != null)
criteria.and("tags").all(tags);
if (writer != null)
criteria.and("writer").is(writer);
this.filter(criteria, sort);
Query query = new Query(criteria);
query.with(new PageRequest(page - 1, size));
this.sorting(query, sort);
return mongoTemplate.find(query, Post.class);
}
示例8: getRepositories
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/** 저장소를 검색
* @param tags
* @param search
* @param creator
* @param sort
* @param page
* @param size
* @return
*/
public List<Repository> getRepositories(
List<String> tags,
String search,
String sort,
int page,
int size) {
Criteria criteria = new Criteria();
if(search != null && search.length()>0)
criteria.orOperator(new Criteria("name").regex(search),
new Criteria("description").regex(search));
if(tags != null)
criteria.and("tags").all(tags);
this.filter(criteria, sort);
Query query = new Query(criteria);
query.with(new PageRequest(page-1, size));
this.sorting(query, sort);
return mongoTemplate.find(query, Repository.class);
}
示例9: getPageRequestFullOrderingMixProvider
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/**
* Sorted direction with ordering and corresponding ORM column.
*/
@Test
public void getPageRequestFullOrderingMixProvider() {
// create a mock URI info with pagination informations
final UriInfo uriInfo = newUriInfo();
uriInfo.getQueryParameters().add(DataTableAttributes.PAGE_LENGTH, "100");
uriInfo.getQueryParameters().add("sidx", "col1");
uriInfo.getQueryParameters().add("sortd", "asc");
final Map<String, String> map = Collections.singletonMap("col1", "colOrm");
final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, map);
Assert.assertNotNull(pageRequest);
Assert.assertNotNull(pageRequest.getSort());
Assert.assertEquals(0, pageRequest.getOffset());
Assert.assertEquals(0, pageRequest.getPageNumber());
Assert.assertNull(pageRequest.getSort().getOrderFor("colOrm?"));
Assert.assertNotNull(pageRequest.getSort().getOrderFor("colOrm"));
Assert.assertEquals(Direction.ASC, pageRequest.getSort().getOrderFor("colOrm").getDirection());
Assert.assertTrue(pageRequest.getSort().getOrderFor("colOrm").isIgnoreCase());
Assert.assertEquals(100, pageRequest.getPageSize());
}
示例10: getCptMinByFilter
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/**
* @param value
* @param inclureDossierOtherYears
* @param exactSearch
* @return la liste des compte grace a un filtre pour la recherche de compte candidat
*/
public List<CompteMinima> getCptMinByFilter(String value, final Boolean inclureDossierOtherYears,
final Boolean exactSearch) {
if (!exactSearch) {
value = "%" + value + "%";
}
if (inclureDossierOtherYears) {
return compteMinimaRepository.findByFilterAllYears(value,
new PageRequest(0, ConstanteUtils.NB_MAX_RECH_CPT_MIN));
} else {
Campagne campagne = campagneController.getCampagneActive();
if (value == null || campagne == null) {
return new ArrayList<>();
}
return compteMinimaRepository.findByFilter(campagne.getCodCamp(), value,
new PageRequest(0, ConstanteUtils.NB_MAX_RECH_CPT_MIN));
}
}
示例11: getPageRequestIdentityMapping
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
/**
* Sorted direction with ordering and corresponding ORM column.
*/
@Test
public void getPageRequestIdentityMapping() {
// create a mock URI info with pagination informations
final UriInfo uriInfo = newUriInfo();
uriInfo.getQueryParameters().add("sidx", "col1");
uriInfo.getQueryParameters().add("sortd", "asc");
final Map<String, String> map = Collections.singletonMap("*", "*");
final PageRequest pageRequest = paginationJson.getPageRequest(uriInfo, map);
Assert.assertNotNull(pageRequest);
Assert.assertNotNull(pageRequest.getSort());
Assert.assertEquals(0, pageRequest.getOffset());
Assert.assertEquals(0, pageRequest.getPageNumber());
Assert.assertNull(pageRequest.getSort().getOrderFor("col1?"));
Assert.assertNotNull(pageRequest.getSort().getOrderFor("col1"));
Assert.assertEquals(Direction.ASC, pageRequest.getSort().getOrderFor("col1").getDirection());
Assert.assertTrue(pageRequest.getSort().getOrderFor("col1").isIgnoreCase());
Assert.assertEquals(10, pageRequest.getPageSize());
}
示例12: testFindByUserIdSorted_withValidQuery_shouldReturnCorrectSortedByPinnedAndLastEditedDescending
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
@Test
public void testFindByUserIdSorted_withValidQuery_shouldReturnCorrectSortedByPinnedAndLastEditedDescending() {
List<Note> firstFive = dao.findByUserIdSorted(1l, new PageRequest(0, 5));
assertEquals("check latest pinned", "1-pinned-latest", firstFive.get(0).getTitle());
assertEquals("check second pinned", "2-pinned-second", firstFive.get(1).getTitle());
assertEquals("check third pinned", "3-pinned-third", firstFive.get(2).getTitle());
assertEquals("check real latest non-pinned", "1latest", firstFive.get(3).getTitle());
assertEquals("check second non-pinned", "2second", firstFive.get(4).getTitle());
List<Note> secondFive = dao.findByUserIdSorted(1l, new PageRequest(1, 5));
assertEquals("check third", "3thrid", secondFive.get(0).getTitle());
assertEquals("check fourth", "4fourth", secondFive.get(1).getTitle());
assertEquals("check fifth", "5fifth", secondFive.get(2).getTitle());
assertEquals("check second oldest", "second oldest", secondFive.get(3).getTitle());
assertEquals("check oldest",
"oldest-non-pinned. Capicola kevin ham hock, pancetta ribeye beef ribs short loin pork loin sirloin tail pig porchetta boudin. Chuck porchetta meatloaf, beef ham swine tenderloin tail.",
secondFive.get(4).getTitle());
}
示例13: getOrCreateDemoIssuer
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
@Override
public IssuerWithKeys getOrCreateDemoIssuer() {
IssuerEntity demoIssuer = issuerRepository.findByName(DEMO_ISSUER_NAME, new PageRequest(0, 1))
.getContent()
.stream()
.findFirst()
.orElseGet(() -> this.createDemoIssuerWithKeys().getIssuer());
String privateKeyBase64 = demoIssuer.getPrivateKeyBase64()
.orElseThrow(IllegalArgumentException::new);
return IssuerWithKeys.builder()
.issuer(demoIssuer)
.publicKey(KeyImpl.fromBase64(demoIssuer.getPublicKeyBase64()))
.privateKey(KeyImpl.fromBase64(privateKeyBase64))
.build();
}
示例14: useSliceToLoadContent
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
@Test
public void useSliceToLoadContent() {
repository.deleteAll();
// int repository with some values that can be ordered
int totalNumberUsers = 11;
List<User> source = new ArrayList<User>(totalNumberUsers);
for (int i = 1; i <= totalNumberUsers; i++) {
User user = new User();
user.setLastname(this.user.getLastname());
user.setUsername(user.getLastname() + "-" + String.format("%03d", i));
source.add(user);
}
repository.save(source);
Slice<User> users = repository.findByLastnameOrderByUsernameAsc(this.user.getLastname(), new PageRequest(1, 5));
assertThat(users, contains(source.subList(5, 10).toArray()));
}
示例15: testFindArchivedNotesByUserIdPaginated_withCorrectUserIdFirstPage4Items_shouldReturnCorrectAndSorted
import org.springframework.data.domain.PageRequest; //導入依賴的package包/類
@Test
public void testFindArchivedNotesByUserIdPaginated_withCorrectUserIdFirstPage4Items_shouldReturnCorrectAndSorted() {
List<OverviewNote> notes = service.findArchivedNotesByUserIdPaginated(1l, new PageRequest(0, 4));
assertEquals("should return 4 notes", 4, notes.size());
assertTrue("should contain first pinned entry", notes.get(0).getTitle().equals("a1-pinned-latest"));
assertTrue("should contain second pinned entry", notes.get(1).getTitle().equals("a2-pinned-second"));
assertTrue("should contain third pinned entry", notes.get(2).getTitle().equals("a3-pinned-third"));
assertTrue("should contain first regular entry", notes.get(3).getTitle().equals("a1latest"));
OverviewNote firstNote = notes.get(0);
Note expectedFirst = archivedDao.findOne(firstNote.getId());
assertEquals("check last edit", expectedFirst.getLastEdit(), firstNote.getLastEdit());
assertEquals("check if part content is part of content",
StringUtils.abbreviate(expectedFirst.getContent(), NotesServiceImpl.OVERVIEW_CONTENT_PART_LENGTH),
firstNote.getPartContent());
assertEquals("check title", expectedFirst.getTitle(), firstNote.getTitle());
assertEquals("check pinned", expectedFirst.getPinned(), firstNote.getPinned());
}