Java Code Examples for org.springframework.data.domain.Page.getContent()

The following are Jave code examples for showing how to use getContent() of the org.springframework.data.domain.Page class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: springboot-learning-example-master   File: CityESServiceImpl.java   Source Code and License Vote up 11 votes
@Override
public List<City> searchCity(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("cityname", searchContent)),
                ScoreFunctionBuilders.weightFactorFunction(1000))
            .add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("description", searchContent)),
                    ScoreFunctionBuilders.weightFactorFunction(100));

    // 创建搜索 DSL 查询
    SearchQuery searchQuery = new NativeSearchQueryBuilder()
            .withPageable(pageable)
            .withQuery(functionScoreQueryBuilder).build();

    LOGGER.info("\n searchCity(): searchContent [" + searchContent + "] \n DSL  = \n " + searchQuery.getQuery().toString());

    Page<City> searchPageResults = cityRepository.search(searchQuery);
    return searchPageResults.getContent();
}
 
Example 2
Project: jhipster-microservices-example   File: EntryResource.java   Source Code and License Vote up 6 votes
/**
 * GET  /entries : get all the entries.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of entries in body
 */
@GetMapping("/entries")
@Timed
public ResponseEntity<List<Entry>> getAllEntries(@ApiParam Pageable pageable) {
    log.debug("REST request to get a page of Entries");
    Page<Entry> page = entryRepository.findByBlogUserLoginOrderByDateDesc(SecurityUtils.getCurrentUserLogin(), pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/entries");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 3
Project: xm-uaa   File: AuditResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /audits : get a page of AuditEvents between the fromDate and toDate.
 *
 * @param fromDate the start of the time period of AuditEvents to get
 * @param toDate the end of the time period of AuditEvents to get
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 */
@GetMapping(params = {"fromDate", "toDate"})
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    @ApiParam Pageable pageable) {

    Page<AuditEvent> page = auditEventService.findByDates(
        fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
        toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant(),
        pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 4
Project: qualitoast   File: ApplicationResource.java   Source Code and License Vote up 5 votes
/**
 * SEARCH  /_search/applications?query=:query : search for the application corresponding
 * to the query.
 *
 * @param query the query of the application search
 * @param pageable the pagination information
 * @return the result of the search
 */
@GetMapping("/_search/applications")
@Timed
public ResponseEntity<List<Application>> searchApplications(@RequestParam String query, Pageable pageable) {
    log.debug("REST request to search for a page of Applications for query {}", query);
    Page<Application> page = applicationService.search(query, pageable);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/applications");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 5
Project: spring-io   File: UserResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /users : get all users.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and with body all users
 */
@GetMapping("/users")
@Timed
public ResponseEntity<List<UserDTO>> getAllUsers(@ApiParam Pageable pageable) {
    final Page<UserDTO> page = userService.getAllManagedUsers(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/users");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 6
Project: xm-ms-entity   File: LinkResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /links : get all the links.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of links in body
 */
@GetMapping("/links")
@Timed
public ResponseEntity<List<Link>> getAllLinks(@ApiParam Pageable pageable) {
    log.debug("REST request to get a page of Links");
    Page<Link> page = linkService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/links");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 7
Project: social-media-analytic-system   File: GraphServiceImpl.java   Source Code and License Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public NotionNodeData findNodeByNotion(String searchText) {
    Page<NotionNodeData> result = nodeRepository.findNodeByNotion(searchText, new PageRequest(0, 1));
    List<NotionNodeData> content = result.getContent();
    if (content.size() > 0){
        return content.get(0);
    }
    return null;
}
 
Example 8
Project: Armory   File: LessonResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /lessons : get all the lessons.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of lessons in body
 */
@GetMapping("/lessons")
@Timed
public ResponseEntity<List<LessonDTO>> getAllLessons(@ApiParam Pageable pageable) {
    log.debug("REST request to get a page of Lessons");
    Page<LessonDTO> page = lessonService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/lessons");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 9
Project: devops-cstack   File: MessageServiceImpl.java   Source Code and License Vote up 5 votes
@Override
public List<Message> listByUser(User user, int nbRows)
        throws ServiceException {
    try {
        Pageable pageable = new PageRequest(0, nbRows, sortByLastNameAsc());
        Page<Message> requestedPage = messageDAO.listByUserAndCuInstance(user, cuInstanceName, pageable);
        return requestedPage.getContent();
    } catch (PersistenceException e) {
        throw new ServiceException(e.getLocalizedMessage(), e);
    }
}
 
Example 10
Project: shoucang   File: ContentResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /contents -> get all the contents.
 */
@RequestMapping(value = "/contents",
    method = RequestMethod.GET,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Content>> getAllContents(Pageable pageable)
    throws URISyntaxException {
    Page<Content> page = contentRepository.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/contents");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 11
Project: qualitoast   File: ResultatResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /resultats : get all the resultats.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of resultats in body
 */
@GetMapping("/resultats")
@Timed
public ResponseEntity<List<Resultat>> getAllResultats(Pageable pageable) {
    log.debug("REST request to get a page of Resultats");
    Page<Resultat> page = resultatService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/resultats");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 12
Project: mongodb-file-server   File: FileServiceImpl.java   Source Code and License Vote up 5 votes
@Override
public List<File> listFilesByPage(int pageIndex, int pageSize) {
	Page<File> page = null;
	List<File> list = null;
	
	Sort sort = new Sort(Direction.DESC,"uploadDate"); 
	Pageable pageable = new PageRequest(pageIndex, pageSize, sort);
	
	page = fileRepository.findAll(pageable);
	list = page.getContent();
	return list;
}
 
Example 13
Project: JavaQuarkBBS   File: AdminUserController.java   Source Code and License Vote up 5 votes
/**
 * 翻页获取管理员
 *
 * @param adminUser
 * @param draw:请求次数
 * @param start
 * @param length
 * @return
 */
@GetMapping
public PageResult getAll(AdminUser adminUser, String draw,
                         @RequestParam(required = false, defaultValue = "1") int start,
                         @RequestParam(required = false, defaultValue = "10") int length) {
    int pageNo = start / length;
    Page<AdminUser> page = adminUserService.findByPage(adminUser, pageNo, length);
    PageResult<List<AdminUser>> result = new PageResult<>(
            draw,
            page.getTotalElements(),
            page.getTotalElements(),
            page.getContent());
    return result;
}
 
Example 14
Project: sentry   File: PermissionResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /permissions : get all the permissions.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of permissions in body
 * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
 */
@GetMapping("/permissions")
@Timed
@Secured(AuthoritiesConstants.SUPPORT)
public ResponseEntity<List<Permission>> getAllPermissions(@ApiParam Pageable pageable)
    throws URISyntaxException {
    log.debug("REST request to get a page of Permissions");
    Page<Permission> page = permissionService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/permissions");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 15
Project: qualitoast   File: ApplicationResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /applications : get all the applications.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of applications in body
 */
@GetMapping("/applications")
@Timed
public ResponseEntity<List<Application>> getAllApplications(Pageable pageable) {
    log.debug("REST request to get a page of Applications");
    Page<Application> page = applicationService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/applications");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 16
Project: sentry   File: AuditResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /audits : get a page of AuditEvents.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
 */
@GetMapping
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<AuditEvent>> getAll(@ApiParam Pageable pageable) throws URISyntaxException {
    Page<AuditEvent> page = auditEventService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 17
Project: xm-ms-entity   File: CommentResource.java   Source Code and License Vote up 5 votes
/**
 * SEARCH  /_search/comments?query=:query : search for the comment corresponding
 * to the query.
 *
 * @param query the query of the comment search
 * @param pageable the pagination information
 * @return the result of the search
 */
@GetMapping("/_search/comments")
@Timed
public ResponseEntity<List<Comment>> searchComments(@RequestParam String query, @ApiParam Pageable pageable) {
    log.debug("REST request to search for a page of Comments for query {}", query);
    Page<Comment> page = commentService.search(query, pageable);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/comments");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 18
Project: role-api   File: PaginationAdvice.java   Source Code and License Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
							  Class<? extends HttpMessageConverter<?>> selectedConverterType,
							  ServerHttpRequest request, ServerHttpResponse response) {
	Page<?> page = (Page<?>) body;
	this.paginationHeadersBuilder.addPaginationData(response.getHeaders(), page);
	return page.getContent();
}
 
Example 19
Project: xm-ms-entity   File: CommentResource.java   Source Code and License Vote up 5 votes
/**
 * GET  /comments : get all the comments.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of comments in body
 */
@GetMapping("/comments")
@Timed
public ResponseEntity<List<Comment>> getAllComments(@ApiParam Pageable pageable) {
    log.debug("REST request to get a page of Comments");
    Page<Comment> page = commentService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/comments");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 20
Project: spring-boot-elastcsearch-example   File: EsBaseDaoImpl.java   Source Code and License Vote up 4 votes
/**
 * @param filedContentMap
 * @param heightFields
 * @param sortField
 * @param order
 * @return
 */
@Override
public List<T> queryList(Map<String, Object> filedContentMap, final List<String> heightFields, String sortField, SortOrder order) {
    Field[] hfields = new Field[0];
    if (heightFields != null) {
        hfields = new Field[heightFields.size()];
        for (int i = 0; i < heightFields.size(); i++) {
            //String o="{\"abc\" : \"[abc]\"}";
            hfields[i] = new Field(heightFields.get(i)).preTags("<em>").postTags("</em>").fragmentSize(250);
        }
    }
    NativeSearchQueryBuilder nsb = new NativeSearchQueryBuilder().withHighlightFields(hfields);//高亮字段
    if (sortField != null && order != null)//排序
        nsb.withSort(new FieldSortBuilder(sortField).ignoreUnmapped(true).order(order));
    BoolQueryBuilder qb = QueryBuilders.boolQuery();
    for (String key : filedContentMap.keySet()) {//字段查询
        qb.must(QueryBuilders.matchQuery(key, filedContentMap.get(key)));

    }
    nsb.withQuery(qb);
    SearchQuery searchQuery = nsb.build();//查询建立
    Page<T> page = null;
    if (heightFields != null && heightFields.size() > 0) {//如果设置高亮
        page = elasticsearchTemplate.queryForPage(searchQuery, entityClass, new SearchResultMapper() {
            @Override
            public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
                List<T> chunk = new ArrayList<T>();
                for (SearchHit searchHit : response.getHits()) {
                    if (response.getHits().getHits().length <= 0) {
                        return null;
                    }

                    Map<String, Object> entityMap = searchHit.getSource();
                    for (String highName : heightFields) {
                        String highValue = searchHit.getHighlightFields().get(highName).fragments()[0].toString();
                        entityMap.put(highName, highValue);
                    }
                    chunk.add((T) PropertyHelper.getFansheObj(entityClass, entityMap));
                }
                if (chunk.size() > 0) {
                    return new AggregatedPageImpl<T>((List<T>) chunk);
                }
                return null;
            }

        });
    } else//如果不设置高亮
        page = elasticsearchTemplate.queryForPage(searchQuery, entityClass);

    return page.getContent();
}