本文整理汇总了Java中org.springframework.data.domain.Page类的典型用法代码示例。如果您正苦于以下问题:Java Page类的具体用法?Java Page怎么用?Java Page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Page类属于org.springframework.data.domain包,在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBy
import org.springframework.data.domain.Page; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public PageWrapper<User> findBy(FindUserDTO dto, int page, int size) {
List<String> roleStr = null;
String usernameOrEmail;
if (dto.getRole() == null) {
if (UserUtils.isAdmin())
roleStr = Arrays.asList(RoleEnum.PROFESSOR.name(), RoleEnum.STUDENT.name());
else if (UserUtils.isProfessor())
roleStr = Arrays.asList(RoleEnum.STUDENT.name());
} else {
roleStr = Arrays.asList(dto.getRole().name());
}
usernameOrEmail = StringUtils.isEmpty(dto.getUsernameOrEmail()) ? "%%" : "%".concat(dto.getUsernameOrEmail().toLowerCase()).concat("%");
Pageable pageable = new PageRequest(page, size);
Page<User> pageInterface = userRepository.findBy(roleStr, usernameOrEmail, pageable);
return new PageWrapper(pageInterface.getContent(), pageable, pageInterface.getTotalElements());
}
示例2: testFindAllWithRulesRange
import org.springframework.data.domain.Page; //导入依赖的package包/类
/**
* Default find all, plenty of string rules : lte, gte
*/
@Test
public void testFindAllWithRulesRange() {
final List<UIRule> rules = new ArrayList<>();
final BasicRule ruleLTE = new BasicRule();
ruleLTE.setData("3");
ruleLTE.setField("dialLong");
ruleLTE.setOp(RuleOperator.LTE);
rules.add(ruleLTE);
final BasicRule ruleGTE = new BasicRule();
ruleGTE.setData("1");
ruleGTE.setField("dialLong");
ruleGTE.setOp(RuleOperator.GTE);
rules.add(ruleGTE);
final UiPageRequest uiPageRequest = newAnd10();
uiPageRequest.getUiFilter().setRules(rules);
final Map<String, String> mapping = newBaseMapping();
final Page<SystemDialect> findAll = paginationDao.findAll(SystemDialect.class, uiPageRequest, mapping, null, null);
Assert.assertTrue(findAll.hasContent());
Assert.assertEquals(3, findAll.getTotalElements());
Assert.assertEquals(3, findAll.getContent().size());
}
示例3: getOperinoComponents
import org.springframework.data.domain.Page; //导入依赖的package包/类
/**
* GET /operinos/:id/components : get the components linked to the "id" operino.
*
* @param id the id of the operino to retrieve components for
* @return the ResponseEntity with status 200 (OK) and with body the operino, or with status 404 (Not Found)
*/
@GetMapping("/operinos/{id}/components")
@Timed
public ResponseEntity<List<OperinoComponent>> getOperinoComponents(@PathVariable Long id, Pageable pageable) throws URISyntaxException {
log.debug("REST request to get components for Operino : {}", id);
Operino operino = operinoService.verifyOwnershipAndGet(id);
if (operino != null) {
Page<OperinoComponent> page = operinoComponentService.findAllByOperino(operino, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/operino-components");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
} else {
return ResponseEntity.badRequest()
.headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "Not authorized", String.valueOf(id))).build();
}
// return ResponseUtil.wrapOrNotFound(Optional.ofNullable(operinoComponentService.findAllByOperino(operino)));
}
示例4: shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange
import org.springframework.data.domain.Page; //导入依赖的package包/类
@Test
public void shouldReturnRedirectToFirstPageWhenRequestedPageIsOutOfRange() {
final Page<Email> page = mock(Page.class);
when(page.getTotalElements()).thenReturn(8L);
when(page.getTotalPages()).thenReturn(2);
when(page.getNumber()).thenReturn(3);
when(page.getNumberOfElements()).thenReturn(5);
when(emailRepository.findAll(any(Pageable.class))).thenReturn(page);
String result = sut.getAll(3, 5, model);
assertEquals(EmailController.REDIRECT_EMAIL_LIST_VIEW, result);
verify(emailRepository).findAll(argThat(matchPageable(3, 5)));
verifyNoMoreInteractions(emailRepository);
}
示例5: index
import org.springframework.data.domain.Page; //导入依赖的package包/类
@GetMapping(value = "/")
public String index(Model model) {
model.addAttribute("home","selected");
Page<ArticleDto> listArticle = articleService.list(0, ArticleUtils.getIsPublished(),ArticleUtils.getIsTweet());
model.addAttribute("articleFirst",listArticle.getContent().get(0));
model.addAttribute("articleLast",listArticle.getContent().get(1));
model.addAttribute("listArticle",listArticle);
List<Course> courseList = courseService.getCourseTopN(2);
model.addAttribute("courseList",courseList);
List<Document> documentList = storageService.getNewDocumentTopN("index",4);
model.addAttribute("documentList",documentList);
return "front/theme/effe/home";
}
示例6: getFormDatas
import org.springframework.data.domain.Page; //导入依赖的package包/类
@ApiOperation(value="分页查询表单内容", notes="根据传进来的查询参数,获取表单内容信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "主键ID", required = false, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "businessKey", value = "业务主键KEY,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "key", value = "内容键,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "value", value = "内容值,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "tenantId", value = "租户ID,模糊匹配", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "page", value = "分页查询,开始查询的页码", defaultValue="0", required = false, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "size", value = "分页查询,每页显示的记录数", defaultValue="10", required = false, dataType = "int", paramType = "query"),
@ApiImplicitParam(name = "sort", value = "排序的字段,可以多值以逗号分割", required = false, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "order", value = "排序的方式,可以为asc或desc,可以多值以逗号分割", required = false, dataType = "string", paramType = "query")
})
@RequestMapping(value = "/form-datas", method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(value = HttpStatus.OK)
public Page<FormData> getFormDatas(@ApiIgnore @RequestParam Map<String, String> requestParams) {
Criteria<FormData> criteria = new Criteria<FormData>();
criteria.add(Restrictions.eq("id", requestParams.get("id"), true));
criteria.add(Restrictions.like("businessKey", requestParams.get("businessKey"), true));
criteria.add(Restrictions.like("key", requestParams.get("key"), true));
criteria.add(Restrictions.like("value", requestParams.get("value"), true));
criteria.add(Restrictions.like("tenantId", requestParams.get("tenantId"), true));
return formDataRepository.findAll(criteria, getPageable(requestParams));
}
示例7: 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";
}
示例8: 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;
}
示例9: 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;
}
示例10: applyPaginationNotLazy
import org.springframework.data.domain.Page; //导入依赖的package包/类
/**
* Pagination test without lazy mode.
*/
@Test
public void applyPaginationNotLazy() {
// create a mock URI info with pagination informations
final UriInfo uriInfo = newUriInfo();
final Page<SystemUser> page = Mockito.mock(Page.class);
final List<SystemUser> list = new ArrayList<>();
uriInfo.getQueryParameters().putSingle(DataTableAttributes.ECHO, "echo");
list.add(new SystemUser());
Mockito.when(page.getContent()).thenReturn(list);
Mockito.when(page.getTotalElements()).thenReturn(1L);
final TableItem<SystemUser> pageRequest = paginationJson.applyPagination(uriInfo, page, Function.identity());
Assert.assertNotNull(pageRequest);
Assert.assertEquals(1, pageRequest.getData().size());
Assert.assertEquals(1, pageRequest.getRecordsTotal());
Assert.assertEquals(1, pageRequest.getRecordsFiltered());
Assert.assertEquals("echo", pageRequest.getDraw());
Assert.assertTrue(pageRequest.getData() instanceof ArrayList<?>);
}
示例11: testUsersGet
import org.springframework.data.domain.Page; //导入依赖的package包/类
@Test
@WithMockAuth(id="1")
public void testUsersGet() throws Exception {
//Telling Mockito to use this mock list every time the findAll method is called on the userRepo
Pageable pr = new PageRequest(0, 2 , Sort.Direction.ASC, "registrationDate", "id" );
Page<User> pageofUser = new PageImpl<>(mockUserList);
given(mockUserRepository.findAll(pr)).willReturn(pageofUser);
//Perform the AP call and check response status code.
mockMvc.perform(get("/api/users?page=0&size=2")).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
//.andExpect(jsonPath("$", hasSize(3)))
.andExpect(jsonPath("$.users[0].id", is(10)))//First user id is 10
.andExpect(jsonPath("$.users[1].id", is(1))) //Second user id is 1.
.andExpect(jsonPath("$.users[0].email", is("[email protected]")))
.andExpect(jsonPath("$.users[1].email", is("[email protected]")));
//We verify that we called findAll method once only on the repository.
verify(mockUserRepository, times(1)).findAll(pr);
verify(mockUserRepository, times(1)).count();
//We verify that we didnt call anything else on the repository
verifyNoMoreInteractions(mockUserRepository);
//We verify that user exist and didnt modify them from the repository
assertEquals(mockIoannisUser, mockUserRepository.findAll(pr).iterator().next());
}
示例12: commaTest
import org.springframework.data.domain.Page; //导入依赖的package包/类
@Test
public void commaTest() {
String baseUrl = "/api/_search/example";
List<String> content = new ArrayList<>();
Page<String> page = new PageImpl<>(content);
String query = "Test1, test2";
HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
List<String> strHeaders = headers.get(HttpHeaders.LINK);
assertNotNull(strHeaders);
assertTrue(strHeaders.size() == 1);
String headerData = strHeaders.get(0);
assertTrue(headerData.split(",").length == 2);
String expectedData = "</api/_search/example?page=0&size=0&query=Test1%2C+test2>; rel=\"last\","
+ "</api/_search/example?page=0&size=0&query=Test1%2C+test2>; rel=\"first\"";
assertEquals(expectedData, headerData);
List<String> xTotalCountHeaders = headers.get("X-Total-Count");
assertTrue(xTotalCountHeaders.size() == 1);
assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(0L));
}
示例13: searchCity
import org.springframework.data.domain.Page; //导入依赖的package包/类
@Override
public List<City> searchCity(Integer pageNumber,
Integer pageSize,
String searchContent) {
// 分页参数
Pageable pageable = new PageRequest(pageNumber, pageSize);
// Function Score Query
FunctionScoreQueryBuilder functionScoreQueryBuilder = QueryBuilders.functionScoreQuery()
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("cityname", searchContent)),
ScoreFunctionBuilders.weightFactorFunction(1000))
.add(QueryBuilders.boolQuery().should(QueryBuilders.matchQuery("description", searchContent)),
ScoreFunctionBuilders.weightFactorFunction(100));
// 创建搜索 DSL 查询
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withPageable(pageable)
.withQuery(functionScoreQueryBuilder).build();
LOGGER.info("\n searchCity(): searchContent [" + searchContent + "] \n DSL = \n " + searchQuery.getQuery().toString());
Page<City> searchPageResults = cityRepository.search(searchQuery);
return searchPageResults.getContent();
}
示例14: queryCompanys
import org.springframework.data.domain.Page; //导入依赖的package包/类
@ApiOperation(value = "queryCompanys", notes = "获取 公司分页")
@GetMapping("/all_company/page")
public ModelResult<List<Company>> queryCompanys(Pageable pageable,
HttpServletRequest request,
HttpServletResponse response) throws URISyntaxException {
ModelResult<List<Company>> result = new ModelResult<>();
Page<Company> companies = companyMapper.selectAllPageable(pageable);
result.setData(companies.getContent());
PaginationUtil.setPaginationHttpHeaders(companies, request,response);
return result;
}
示例15: searchUserPosts
import org.springframework.data.domain.Page; //导入依赖的package包/类
@Query("{" +
" \"bool\": {" +
" \"must\": [" +
" {" +
" \"term\": {" +
" \"user.login\": \"?1\"" +
" }" +
" }, " +
" {" +
" \"bool\": {" +
" \"should\": [" +
" {" +
" \"match\": {" +
" \"title\": \"?0\"" +
" }" +
" }, " +
" {" +
" \"match\": {" +
" \"tags.friendly_name\": \"?0\"" +
" }" +
" }" +
" ]" +
" }" +
" }" +
" ]" +
" }" +
" }")
Page<Post> searchUserPosts(String query, String login, Pageable pageable);