本文整理汇总了Java中org.springframework.data.domain.Page.getNumber方法的典型用法代码示例。如果您正苦于以下问题:Java Page.getNumber方法的具体用法?Java Page.getNumber怎么用?Java Page.getNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.domain.Page
的用法示例。
在下文中一共展示了Page.getNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSearchPaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generateSearchPaginationHttpHeaders(String query, 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()) + "&query=" + query + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + "&query=" + query + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + "&query=" + query + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + "&query=" + query + ">; 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)
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;
}
示例3: generateSearchPaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generateSearchPaginationHttpHeaders(String query, Page page, String baseUrl) {
String escapedQuery = query.replace(",", "%2C");
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;
}
示例4: 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;
}
示例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: 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<Product> products = productService.findAllProductsPageable(new PageRequest(evalPage, evalPageSize));
Pager pager = new Pager(products.getTotalPages(), products.getNumber(), BUTTONS_TO_SHOW);
ModelAndView modelAndView = new ModelAndView();
// Collection<Post> posts = postService.findNLatestPosts(5);
modelAndView.addObject("products", products);
modelAndView.addObject("selectedPageSize", evalPageSize);
modelAndView.addObject("pageSizes", PAGE_SIZES);
modelAndView.addObject("pager", pager);
modelAndView.setViewName("home");
return modelAndView;
}
示例7: 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;
}
示例8: generateSearchPaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generateSearchPaginationHttpHeaders(String query, Page page, String baseUrl) {
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()) + "&query=" + query + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + "&query=" + query + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + "&query=" + query + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + "&query=" + query + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例9: 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;
}
示例10: 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", "" + 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;
}
示例11: homepage
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
@GetMapping("/")
public ModelAndView homepage(@RequestParam("pageSize") Optional<Integer> pageSize,
@RequestParam("page") Optional<Integer> page){
if(clientrepository.count()!=0){
;//pass
}else{
addtorepository();
}
ModelAndView modelAndView = new ModelAndView("index");
//
// 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;
// print repo
System.out.println("here is client repo " + clientrepository.findAll());
Page<ClientModel> clientlist = clientrepository.findAll(new PageRequest(evalPage, evalPageSize));
System.out.println("client list get total pages" + clientlist.getTotalPages() + "client list get number " + clientlist.getNumber());
PagerModel pager = new PagerModel(clientlist.getTotalPages(),clientlist.getNumber(),BUTTONS_TO_SHOW);
// add clientmodel
modelAndView.addObject("clientlist",clientlist);
// evaluate page size
modelAndView.addObject("selectedPageSize", evalPageSize);
// add page sizes
modelAndView.addObject("pageSizes", PAGE_SIZES);
// add pager
modelAndView.addObject("pager", pager);
return modelAndView;
}
示例12: mapPage
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static <S, T> Page<T> mapPage(Page<S> source, Class<T> targetClass) {
List<S> sourceList = source.getContent();
List<T> list = new ArrayList<>();
for (int i = 0; i < sourceList.size(); i++) {
T target = INSTANCE.map(sourceList.get(i), targetClass);
list.add(target);
}
return new PageImpl<>(list, new PageRequest(source.getNumber(), source.getSize(), source.getSort()),
source.getTotalElements());
}
示例13: 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;
}
示例14: generateSearchPaginationHttpHeaders
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
public static HttpHeaders generateSearchPaginationHttpHeaders(String query, Page<?> page, String baseUrl)
throws URISyntaxException, UnsupportedEncodingException {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", "" + page.getTotalElements());
String link = "";
String queryUrl = URLEncoder.encode(query, "UTF-8");
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + "&query=" + queryUrl + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + "&query=" + queryUrl + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + "&query=" + queryUrl + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + "&query=" + queryUrl + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例15: getAllEmailsPaged
import org.springframework.data.domain.Page; //导入方法依赖的package包/类
private String getAllEmailsPaged(int page, int size, Model model) {
if(page < 0 || size <= 0){
return REDIRECT_EMAIL_LIST_VIEW;
}
Page<Email> result = emailRepository.findAll(new PageRequest(page, size, DEFAULT_SORT));
if (result.getNumber() != 0 && result.getNumber() >= result.getTotalPages()) {
return REDIRECT_EMAIL_LIST_VIEW;
}
model.addAttribute(EMAIL_LIST_MODEL_NAME, result);
return EMAIL_LIST_VIEW;
}