Package org.springframework.data.domain

Examples of org.springframework.data.domain.Pageable


        for (int i = 0; i < count; i++) {
            lastUser = userService.save(createUser());
        }

        Sort sortAsc = new Sort(Sort.Direction.ASC, "id");
        Pageable pageable = new PageRequest(0, 5, sortAsc);
        Page<User> userPage = userService.findAll(pageable);

        assertEquals(5, userPage.getNumberOfElements());
        assertFalse(userPage.getContent().contains(lastUser));
        assertTrue(userPage.getContent().get(0).getId() < userPage.getContent().get(1).getId());
View Full Code Here


        for (int i = 0; i < count; i++) {
            lastUser = userService.save(createUser());
        }

        Sort sortAsc = new Sort(Sort.Direction.ASC, "id");
        Pageable pageable = new PageRequest(0, 5, sortAsc);
        Map<String, Object> searchParams = new HashMap<String, Object>();
        searchParams.put("username_like", "zhang");
        Searchable search = Searchable.newSearchable(searchParams).setPage(pageable);

        Page<User> userPage = userService.findAll(search);
View Full Code Here

    }

    public void reweight() {
        int batchSize = 100;
        Sort sort = new Sort(Sort.Direction.DESC, "weight");
        Pageable pageable = new PageRequest(0, batchSize, sort);
        Page<M> page = findAll(pageable);
        do {
            //doReweight需要requiresNew事务
            ((BaseMovableService) AopContext.currentProxy()).doReweight(page);

            RepositoryHelper.clear();

            if (page.isLastPage()) {
                break;
            }

            pageable = new PageRequest((pageable.getPageNumber() + 1) * batchSize, batchSize, sort);

            page = findAll(pageable);

        } while (true);
    }
View Full Code Here

        return page.getContent().get(0).getWeight() + stepLength;
    }

    public M findPreByWeight(Integer weight) {
        Pageable pageable = new PageRequest(0, 1);
        Map<String, Object> searchParams = Maps.newHashMap();
        searchParams.put("weight_lt", weight);
        Sort sort = new Sort(Sort.Direction.DESC, "weight");
        Page<M> page = findAll(Searchable.newSearchable(searchParams).addSort(sort).setPage(pageable));
View Full Code Here

        }
        return null;
    }

    public M findNextByWeight(Integer weight) {
        Pageable pageable = new PageRequest(0, 1);

        Map<String, Object> searchParams = Maps.newHashMap();
        searchParams.put("weight_gt", weight);
        Sort sort = new Sort(Sort.Direction.ASC, "weight");
        Page<M> page = findAll(Searchable.newSearchable(searchParams).addSort(sort).setPage(pageable));
View Full Code Here

        request.setParameter("page.pn", String.valueOf(pn));
        request.setParameter("page.size", String.valueOf(pageSize));

        MethodParameter parameter = new MethodParameter(pageable, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

        //内部会自动-1,从0开始
        assertEquals(pn - 1, pageable.getPageNumber());
        assertEquals(pageSize, pageable.getPageSize());
        assertEquals(null, pageable.getSort());
    }
View Full Code Here

        request.setParameter("sort.id", "desc");
        request.setParameter("sort.baseInfo.realname", "asc");

        MethodParameter parameter = new MethodParameter(pageableAndSort, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

        //内部会自动-1,从0开始
        assertEquals(pn - 1, pageable.getPageNumber());
        assertEquals(pageSize, pageable.getPageSize());
        Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname").and(new Sort(Sort.Direction.DESC, "id"));
        assertEquals(expectedSort, pageable.getSort());
    }
View Full Code Here

        request.setParameter("sort1.baseInfo.realname", "asc");
        request.setParameter("sort2.id", "desc");

        MethodParameter parameter = new MethodParameter(pageableAndSort, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

        //内部会自动-1,从0开始
        assertEquals(pn - 1, pageable.getPageNumber());
        assertEquals(pageSize, pageable.getPageSize());
        Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname").and(new Sort(Sort.Direction.DESC, "id"));
        assertEquals(expectedSort, pageable.getSort());
    }
View Full Code Here

    @Test
    public void testMethodDefaultPageable() throws Exception {
        MethodParameter parameter = new MethodParameter(methodDefaultPageable, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

        assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber());
        assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize());

        Sort expectedSort = new Sort(Sort.Direction.DESC, "id").and(new Sort(Sort.Direction.ASC, "name"));
        assertEquals(expectedSort, pageable.getSort());
    }
View Full Code Here

    @Test
    public void testParameterDefaultPageable() throws Exception {
        MethodParameter parameter = new MethodParameter(parameterDefaultPageable, 0);
        NativeWebRequest webRequest = new ServletWebRequest(request);
        Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null);

        assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber());
        assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize());
        Sort expectedSort = new Sort(Sort.Direction.DESC, "id").and(new Sort(Sort.Direction.ASC, "name"));
        assertEquals(expectedSort, pageable.getSort());

    }
View Full Code Here

TOP

Related Classes of org.springframework.data.domain.Pageable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.