本文整理汇总了Java中org.springframework.data.domain.Page.getTotalPages方法的典型用法代码示例。如果您正苦于以下问题:Java Page.getTotalPages方法的具体用法?Java Page.getTotalPages怎么用?Java Page.getTotalPages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.domain.Page
的用法示例。
在下文中一共展示了Page.getTotalPages方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generatePaginationHttpHeaders(Page page, String baseUrl) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", Long.toString(page.getTotalElements()));
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例2: generatePaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generatePaginationHttpHeaders(Page page, String baseUrl) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", "" + Long.toString(page.getTotalElements()));
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例3: generatePaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generatePaginationHttpHeaders(Page<?> page, String baseUrl)
throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", "" + page.getTotalElements());
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + (new URI(baseUrl +"?page=" + (page.getNumber() + 1) + "&size=" + page.getSize())).toString() + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + (new URI(baseUrl +"?page=" + (page.getNumber() - 1) + "&size=" + page.getSize())).toString() + ">; rel=\"prev\",";
}
// last and first link
link += "<" + (new URI(baseUrl +"?page=" + (page.getTotalPages() - 1) + "&size=" + page.getSize())).toString() + ">; rel=\"last\",";
link += "<" + (new URI(baseUrl +"?page=" + 0 + "&size=" + page.getSize())).toString() + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例4: list
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@RequestMapping(path="/list")
public String list(DictionarySearchCriteria criteria
, Map<String, Object> model) {
// setting default pageSize and sortFields
if (criteria.isFirstInitialized()) {
criteria.setPageSize(10);
criteria.setSortFields("id:asc");
}
// logger.info("----------------------{}-------------------------", DictionaryType.PREDEFINED);
Page<Dictionary> searchResult = this.dictionaryService.findAll(criteria.getPageable());
Pagination pagination = new Pagination(criteria.getPageNo(), searchResult.getTotalPages(), searchResult.getTotalElements());
model.put("searchResult", searchResult);
model.put("criteria", criteria);
model.put("pagination", pagination);
return "tool/dictionary_list";
}
示例5: home
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@GetMapping("/home")
public ModelAndView home(@RequestParam("pageSize") Optional<Integer> pageSize,
@RequestParam("page") Optional<Integer> page) {
// Evaluate page size. If requested parameter is null, return initial
// page size
int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
// Evaluate page. If requested parameter is null or less than 0 (to
// prevent exception), return initial size. Otherwise, return value of
// param. decreased by 1.
int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;
// Page<Post> posts = postService.findAllPageable(new PageRequest(evalPage, evalPageSize));
Page<Post> posts = postService.findAllOrderedByDatePageable(new PageRequest(evalPage, evalPageSize));
Pager pager = new Pager(posts.getTotalPages(), posts.getNumber(), BUTTONS_TO_SHOW);
ModelAndView modelAndView = new ModelAndView();
// Collection<Post> posts = postService.findNLatestPosts(5);
modelAndView.addObject("posts", posts);
modelAndView.addObject("selectedPageSize", evalPageSize);
modelAndView.addObject("pageSizes", PAGE_SIZES);
modelAndView.addObject("pager", pager);
modelAndView.setViewName("home");
return modelAndView;
}
示例6: listUsersInternal
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
private String listUsersInternal(String search, int pageNumber, Model model) {
if (search == null) {
search = "";
}
// Page numbers in the URL start with 1
PageRequest pageable = new PageRequest(pageNumber - 1, MAX_PAGE_SIZE);
Page<UisUser> usersPage = uisUserService.findAllMatching(search, pageable);
List<UisUser> users = usersPage.getContent();
// If the user tries to access a page that doesn't exist
if (users.size() == 0 && usersPage.getTotalElements() != 0) {
int lastPage = usersPage.getTotalPages();
return "redirect:/admin/users/page/" + lastPage + "?search=" + search;
}
model.addAttribute("page", usersPage);
model.addAttribute("search", search);
return "admin/users";
}
示例7: generatePaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generatePaginationHttpHeaders(Page<?> page, String baseUrl)
throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", "" + page.getTotalElements());
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例8: list
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
/**
*文章列表
* @param page
* @param pageSize
* @param model
* @return
*/
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(@RequestParam(value = "page", defaultValue = "0") Integer page, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, Model model) {
if(page !=0) page = page -1;
Page<ArticleDto> articleList = articleService.list(page);
model.addAttribute("articleList",articleList);
PageUtils pageUtils = new PageUtils("/admin/article/list?",page,articleList.getTotalPages(),articleList.getTotalElements(),pageSize);
model.addAttribute("pb",pageUtils);
return "admin/article/a_list";
}
示例9: generateSearchPaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generateSearchPaginationHttpHeaders(String query, Page page, String baseUrl) {
String escapedQuery;
try {
escapedQuery = URLEncoder.encode(query, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", Long.toString(page.getTotalElements()));
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + "&query=" + escapedQuery + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + "&query=" + escapedQuery + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + "&query=" + escapedQuery + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + "&query=" + escapedQuery + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例10: list
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
/**
* 资源列表
* @param model
* @return
*/
@LeftMenu(name = "资源列表",descritpion = "admin_permission_list",pname = "资源管理",url = "/admin/permission/list",operation = "list")
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(@RequestParam(value = "page", defaultValue = "0") Integer page,Model model) {
if(page !=0) page = page -1;
Page<SysPermission> permissionList = permissionService.list(page);
model.addAttribute("permissionList",permissionList);
PageUtils pageUtils = new PageUtils("/admin/permission/list?",page,permissionList.getTotalPages(),permissionList.getTotalElements(),itweetProperties.getPagSize());
model.addAttribute("pb",pageUtils);
return "admin/user/p_list";
}
示例11: available
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@Transactional // 必须包含该行,不只是懒加载问题,而是需要 transactional EntityManager available (无法得到FullTextEntityManager)
@Override
public Page<Article> search(String query, Pageable pageable) {
Page<SearchResult<Article>> results = articleRepository.search(query, pageable);
List<Article> articles = new ArrayList<>();
results.getContent().forEach(item -> articles.add(item.getEntity()));
return new PageImpl<>(articles, pageable, results.getTotalPages());
}
示例12: 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";
}
示例13: tweet
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@GetMapping(value = "/tweet")
public String tweet(@RequestParam(value = "page", defaultValue = "0") Integer page,Model model) {
if(page != 0) page = page -1;
model.addAttribute("tweet","selected");
Page<ArticleDto> listArticle = articleService.list(page, ArticleUtils.getIsPublished(),ArticleUtils.getIsTweet());
model.addAttribute("listArticle",listArticle);
PageUtils pageUtils = new PageUtils("/tweet",page,listArticle.getTotalPages(),listArticle.getTotalElements(),itweetProperties.getPagSize());
model.addAttribute("pb",pageUtils);
return "front/theme/effe/tweet";
}
示例14: list
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(@RequestParam(value = "page", defaultValue = "0") Integer page,Model model) {
if(page !=0) page = page -1;
Page<Course> courseList = courseService.list(page);
model.addAttribute("courseList",courseList);
PageUtils pageUtils = new PageUtils("/admin/course/list?",page,courseList.getTotalPages(),courseList.getTotalElements(),itweetProperties.getPagSize());
model.addAttribute("pb",pageUtils);
return "admin/course/list";
}