本文整理汇总了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";
}
示例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);
}
示例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);
}
示例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";
}
示例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()));
});
}
示例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()));
});
}
示例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");
}
示例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));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}