當前位置: 首頁>>代碼示例>>Java>>正文


Java Page.getTotalPages方法代碼示例

本文整理匯總了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;
    }
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:23,代碼來源:PaginationUtil.java

示例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;
    }
 
開發者ID:SGKhmCs,項目名稱:speakTogether,代碼行數:23,代碼來源:PaginationUtil.java

示例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;
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:20,代碼來源:PaginationUtil.java

示例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";
	}
 
開發者ID:Kevin-Huang-NZ,項目名稱:springboot-jsp-generator,代碼行數:17,代碼來源:DictionaryController.java

示例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;
    }
 
開發者ID:reljicd,項目名稱:spring-boot-blog,代碼行數:26,代碼來源:HomeController.java

示例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";
}
 
開發者ID:university-information-system,項目名稱:uis,代碼行數:23,代碼來源:AdminUsersController.java

示例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;
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:24,代碼來源:PaginationUtil.java

示例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";
}
 
開發者ID:realxujiang,項目名稱:itweet-boot,代碼行數:20,代碼來源:ArticleController.java

示例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;
}
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:28,代碼來源:PaginationUtil.java

示例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";
}
 
開發者ID:realxujiang,項目名稱:itweet-boot,代碼行數:20,代碼來源:PermissionController.java

示例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());
}
 
開發者ID:chaokunyang,項目名稱:amanda,代碼行數:9,代碼來源:ArticleServiceImpl.java

示例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";
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:41,代碼來源:TagsController.java

示例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";
}
 
開發者ID:realxujiang,項目名稱:itweet-boot,代碼行數:14,代碼來源:EffeController.java

示例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";
}
 
開發者ID:realxujiang,項目名稱:itweet-boot,代碼行數:13,代碼來源:CourseController.java


注:本文中的org.springframework.data.domain.Page.getTotalPages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。