当前位置: 首页>>代码示例>>Java>>正文


Java Page.forEach方法代码示例

本文整理汇总了Java中org.springframework.data.domain.Page.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java Page.forEach方法的具体用法?Java Page.forEach怎么用?Java Page.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.domain.Page的用法示例。


在下文中一共展示了Page.forEach方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: show

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@RequestMapping(value = "/u/{username}", method = RequestMethod.GET)
public String show(@PathVariable String username, Model model) {
    User user = userRepository.findByLogin(username);

    if (user == null) {
        throw new PageNotFoundException("User " + username + " is not found.");
    }

    Page<Post> posts = postRepository.findUserPostsByStatus(user.getId(), PostStatus.PUBLIC, new PageRequest(0, 20));

    List<Long> ids = new ArrayList<>();
    posts.forEach(post -> ids.add(post.getId()));

    model.addAttribute("user", user);
    model.addAttribute("posts", posts);
    model.addAttribute("votes", new HashMap<Long, Vote>());
    model.addAttribute("counting", countingService.getPostListCounting(ids));

    return "users/show";
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:21,代码来源:UsersController.java

示例2: findAllQuestion

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Override
public PageDTO findAllQuestion(int page) {
    Page<Question> list = questionRepository.findAll(new PageRequest(page,10,
            new Sort(Sort.Direction.DESC,"creationDate")));
    List<QuestionDTO> DTOs = new ArrayList<>();
    list.forEach(question -> DTOs.add(new QuestionDTO(question,questionVoteRepository.countAllByQuestion(question))));
    return new PageDTO(list,DTOs);
}
 
开发者ID:Nbsaw,项目名称:miaohu,代码行数:9,代码来源:QuestionServiceImpl.java

示例3: findAllByQuestionId

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Override
public PageDTO<List<AnswerDTO>> findAllByQuestionId(Long questionId, int page) {
    Page<Answer> list = answerRepository.findAll(
            new PageRequest(page,5, new Sort(Sort.Direction.DESC,"creationDate")));
    List<AnswerDTO> DTOs = new ArrayList<>();
    list.forEach(answer -> DTOs.add(new AnswerDTO(answer,answerVoteRepository.countAllByAnswer(answer))));
    return new PageDTO(list,DTOs);
}
 
开发者ID:Nbsaw,项目名称:miaohu,代码行数:9,代码来源:AnswerServiceImpl.java

示例4: index

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
/**
 * 热门标签,搜素标签
 */
@RequestMapping(value = "/tags", method = GET)
@Timed
public String index(Model model, @RequestParam(defaultValue = "1") int page, @RequestParam(required = false) String search) {
    long pages;
    page = page < 1 ? 1 : page - 1;

    Page<Tag> tags;

    if (search == null || search.trim().isEmpty()) {
        tags = tagService.getHotTags(page, PAGE_SIZE);
        long size = tagService.countTags();
        pages = size / PAGE_SIZE + (size % PAGE_SIZE != 0 ? 1 : 0);
    } else {
        // Do search tags
        tags = tagRepository.searchTags(
            search.toUpperCase(),
            new PageRequest(page, PAGE_SIZE, Sort.Direction.DESC, "postCount", "followersCount"));

        pages = tags.getTotalPages();
    }

    model.addAttribute("search", search == null ? "" : search.trim());
    model.addAttribute("tags", tags);
    model.addAttribute("page", page + 1);
    model.addAttribute("totalPages", pages);

    // Check whether the current user already followed the tags or not
    Map<Long, Boolean> followed = new HashMap<>();
    if (SecurityUtils.isAuthenticated()) {
        List<Long> tagIds = new ArrayList<>();
        tags.forEach(tag -> tagIds.add(tag.getId()));
        followed = tagService.isUserFollowedTags(tagIds, userService.getCurrentUserId());
    }
    model.addAttribute("followed", followed);

    return "tags/index";
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:41,代码来源:TagsController.java

示例5: initHotPosts

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Transactional(readOnly = true)
public void initHotPosts() {
    PageRequest page = new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.DESC, "id");
    Page<Post> posts = postRepository.findPublicPosts(page, PostStatus.PUBLIC);
    posts.forEach(post -> {
        this.addHotPost(post);
        this.addTaggedPost(post, tagRepository.findPostTags(post.getId()));
    });
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:10,代码来源:HotPostService.java

示例6: initNewPosts

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Transactional(readOnly = true)
public void initNewPosts() {
    // Load all post ids from database to Redis
    PageRequest page = new PageRequest(0, Integer.MAX_VALUE, Sort.Direction.ASC, "id");
    Page<Post> posts = postRepository.findPublicPosts(page, PostStatus.PUBLIC);
    posts.forEach(post -> {
        this.add(post);
        this.addTaggedPost(post, tagRepository.findPostTags(post.getId()));
    });
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:11,代码来源:NewPostsService.java

示例7: test

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
	ResponseEntity<Page<Person>> persons = service.getPersons(0);
	Page<Person> page = persons.getBody();
	page.forEach(p -> p.setVersion(new Date(1512055286373L)));
	mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
	String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(page);
	WritingJsonValidator.validate(json, "json/PersonRestServiceTest-persons.json");
}
 
开发者ID:appNG,项目名称:appng-examples,代码行数:10,代码来源:PersonRestServiceTest.java

示例8: testPage

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Test
public void testPage() {
    int page = 0, size = 10;
    Sort sort = new Sort(Sort.Direction.DESC, "id");
    Pageable pageable = new PageRequest(page, size, sort);
    Page<User> all = userRepository.findAll(pageable);
    all.forEach(e -> log.info("testPage:{}", e));
}
 
开发者ID:MonkeysAndDogs,项目名称:banana,代码行数:9,代码来源:UserRepositoryTest.java

示例9: getRecentSession

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
/**
 * 查询最新会话
 * @param userId 用户ID
 * @param lastUpdateTime 最后更新时间
 * @return 会话列表
 * @since  1.0
 */
@GetMapping(path = "/recentSession")
public BaseModel<List<SessionEntity>> getRecentSession(@RequestParam("userId") long userId,
        @RequestParam("updateTime") int lastUpdateTime) {

    SearchCriteria<IMRecentSession> recentSessionCriteria = new SearchCriteria<>();
    recentSessionCriteria.add(JpaRestrictions.eq("userId", userId, false));
    recentSessionCriteria.add(JpaRestrictions.eq("status", 0, false));
    recentSessionCriteria.add(JpaRestrictions.gt("updated", lastUpdateTime, false));

    // 取最多100条
    Sort sort = new Sort(Sort.Direction.DESC, "updated");
    Pageable pageParam = new PageRequest(0, 100, sort);
    Page<IMRecentSession> recentSessions = recentSessionRepository.findAll(recentSessionCriteria, pageParam);

    BaseModel<List<SessionEntity>> sessionRes = new BaseModel<List<SessionEntity>>();

    List<SessionEntity> recentInfoList = new ArrayList<>();
    if (recentSessions.getSize() > 0) {
        recentSessions.forEach(recentSession -> {

            SessionEntity recentInfo = new SessionEntity();
            recentInfo.setId(recentSession.getId());
            recentInfo.setPeerId(recentSession.getPeerId());
            recentInfo.setPeerType(recentSession.getType());
            recentInfo.setTalkId(recentSession.getUserId());
            recentInfo.setLatestMsgType(recentSession.getType());
            recentInfo.setCreated(recentSession.getCreated());
            recentInfo.setUpdated(recentSession.getUpdated());
            recentInfoList.add(recentInfo);
        });
    }

    return sessionRes;
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:42,代码来源:RecentSessionServiceController.java

示例10: getPublishedArticleByPage

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Override
public Page<Article> getPublishedArticleByPage(int pageNum, int pageSize) {
    Page<Article> articles = articleRepository.findByStatus(
            new PageRequest(pageNum, pageSize, Sort.Direction.DESC, "id"), 2);
    articles.forEach(article -> {
        int moreIndex = article.getContent().indexOf("<!--more-->");
        if (moreIndex > 0) {
            article.setContent(article.getContent().substring(0, moreIndex));
        }
    });
    return articles;
}
 
开发者ID:fku233,项目名称:Plum,代码行数:13,代码来源:ArticleServiceImpl.java

示例11: findByNameStartingWith

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Test
public void findByNameStartingWith() {
	Page<TopicView> topics = service.listByStartingName("S", PageRequest.of(0, 10));

	assertEquals(topics.getTotalElements(), 3);
	topics.forEach(System.out::println);
}
 
开发者ID:spring-sprout,项目名称:osoon,代码行数:8,代码来源:TopicServiceTest.java

示例12: findByTitle

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Test
public void findByTitle() {
	Page<Meeting> list = meetingRepository.findByTitleContainsAndMeetingStatus("테", Meeting.MeetingStatus.PUBLISHED, PageRequest.of(0, 10, Sort.Direction.DESC, "createdAt"));
	list.forEach(System.out::println);
}
 
开发者ID:spring-sprout,项目名称:osoon,代码行数:6,代码来源:MeetingRepositoryTest.java

示例13: findAllWithCount

import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Test
public void findAllWithCount() {
	Page<TopicView> allWithCount = topicRepository.findAllWithCount(PageRequest.of(0, 10));
	allWithCount.forEach(System.out::println);
}
 
开发者ID:spring-sprout,项目名称:osoon,代码行数:6,代码来源:TopicRepositoryTest.java


注:本文中的org.springframework.data.domain.Page.forEach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。