org.springframework.data.domain.Sort.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(234)

本文整理了Java中org.springframework.data.domain.Sort.<init>()方法的一些代码示例,展示了Sort.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.<init>()方法的具体详情如下:
包路径:org.springframework.data.domain.Sort
类名称:Sort
方法名:<init>

Sort.<init>介绍

[英]Creates a new Sort instance.
[中]创建一个新的排序实例。

代码示例

代码示例来源:origin: spring-projects/spring-batch

  1. @Test
  2. public void testSettingCurrentItemCountExplicitly() throws Exception {
  3. reader.setCurrentItemCount(3);
  4. reader.setPageSize(2);
  5. PageRequest request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id"));
  6. when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
  7. add("3");
  8. add("4");
  9. }}));
  10. request = PageRequest.of(2, 2, new Sort(Direction.ASC, "id"));
  11. when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
  12. add("5");
  13. add("6");
  14. }}));
  15. reader.open(new ExecutionContext());
  16. Object result = reader.read();
  17. assertEquals("3", result);
  18. assertEquals("4", reader.read());
  19. assertEquals("5", reader.read());
  20. assertEquals("6", reader.read());
  21. }

代码示例来源:origin: spring-projects/spring-batch

  1. @Test
  2. public void testResetOfPage() throws Exception {
  3. reader.setPageSize(2);
  4. PageRequest request = PageRequest.of(0, 2, new Sort(Direction.ASC, "id"));
  5. when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
  6. add("1");
  7. add("2");
  8. }}));
  9. request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id"));
  10. when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
  11. add("3");
  12. add("4");
  13. }}));
  14. ExecutionContext executionContext = new ExecutionContext();
  15. reader.open(executionContext);
  16. Object result = reader.read();
  17. reader.close();
  18. assertEquals("1", result);
  19. reader.open(executionContext);
  20. assertEquals("1", reader.read());
  21. assertEquals("2", reader.read());
  22. assertEquals("3", reader.read());
  23. }

代码示例来源:origin: spring-projects/spring-batch

  1. @Test
  2. public void testSettingCurrentItemCountRestart() throws Exception {
  3. reader.setCurrentItemCount(3);
  4. reader.setPageSize(2);
  5. PageRequest request = PageRequest.of(1, 2, new Sort(Direction.ASC, "id"));
  6. when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
  7. add("3");
  8. add("4");
  9. }}));
  10. request = PageRequest.of(2, 2, new Sort(Direction.ASC, "id"));
  11. when(repository.findAll(request)).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
  12. add("5");
  13. add("6");
  14. }}));
  15. ExecutionContext executionContext = new ExecutionContext();
  16. reader.open(executionContext);
  17. Object result = reader.read();
  18. reader.update(executionContext);
  19. reader.close();
  20. assertEquals("3", result);
  21. reader.open(executionContext);
  22. assertEquals("4", reader.read());
  23. assertEquals("5", reader.read());
  24. assertEquals("6", reader.read());
  25. }

代码示例来源:origin: spring-projects/spring-integration

  1. private static Query whereGroupIdOrder(Object groupId) {
  2. return whereGroupIdIs(groupId).with(new Sort(Sort.Direction.DESC, GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
  3. }

代码示例来源:origin: spring-projects/spring-integration

  1. private void updateGroup(Object groupId, Update update) {
  2. Query query = whereGroupIdIs(groupId).with(new Sort(Sort.Direction.DESC, GROUP_UPDATE_TIMESTAMP_KEY, SEQUENCE));
  3. this.template.updateFirst(query, update, this.collectionName);
  4. }

代码示例来源:origin: Exrick/x-boot

  1. public static Pageable initPage(PageVo page){
  2. Pageable pageable=null;
  3. int pageNumber=page.getPageNumber();
  4. int pageSize=page.getPageSize();
  5. String sort=page.getSort();
  6. String order=page.getOrder();
  7. if(pageNumber<1){
  8. pageNumber=1;
  9. }
  10. if(pageSize<1){
  11. pageSize=10;
  12. }
  13. if(StrUtil.isNotBlank(sort)) {
  14. Sort.Direction d;
  15. if(StrUtil.isBlank(order)) {
  16. d = Sort.Direction.DESC;
  17. }else {
  18. d = Sort.Direction.valueOf(order.toUpperCase());
  19. }
  20. Sort s = new Sort(d,sort);
  21. pageable = PageRequest.of(pageNumber-1, pageSize,s);
  22. }else {
  23. pageable = PageRequest.of(pageNumber-1, pageSize);
  24. }
  25. return pageable;
  26. }
  27. }

代码示例来源:origin: spring-projects/spring-data-solr

  1. /**
  2. * Creates a new {@link SolrPageRequest} with sort parameters applied.
  3. *
  4. * @param page zero-based page index.
  5. * @param size the size of the page to be returned.
  6. * @param direction the direction of the {@link Sort} to be specified, can be {@literal null}.
  7. * @param properties the properties to sort by, must not be {@literal null} or empty.
  8. */
  9. public SolrPageRequest(int page, int size, Direction direction, String... properties) {
  10. this(page, size, new Sort(direction, properties));
  11. }

代码示例来源:origin: naver/ngrinder

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void testGetTestListByKeyWord() {
  4. String strangeName = "DJJHG^%R&*^%^565(^%&^%(^%(^";
  5. createPerfTest(strangeName, Status.READY, new Date());
  6. ModelMap model = new ModelMap();
  7. Sort sort = new Sort("testName");
  8. Pageable pageable = new PageRequest(0, 10, sort);
  9. controller.getAll(getTestUser(), strangeName, null, null, pageable, model);
  10. Page<PerfTest> testPage = (Page<PerfTest>) model.get("testListPage");
  11. List<PerfTest> testList = testPage.getContent();
  12. assertThat(testList.size(), is(1));
  13. controller.getAll(getTestUser(), strangeName.substring(2, 10), null, null, new PageRequest(0, 10), model);
  14. testPage = (Page<PerfTest>) model.get("testListPage");
  15. testList = testPage.getContent();
  16. assertThat(testList.size(), is(1));
  17. }

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

  1. /**
  2. * 测试排序
  3. */
  4. @RequestMapping("/sort")
  5. public List<Person> sort() {
  6. List<Person> people = personRepository.findAll(new Sort(Direction.ASC, "age"));
  7. return people;
  8. }

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

  1. /**
  2. * 测试排序
  3. */
  4. @RequestMapping("/sort")
  5. public List<Person> sort() {
  6. List<Person> people = personRepository.findAll(new Sort(Direction.ASC, "age"));
  7. return people;
  8. }

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

  1. /**
  2. * 测试排序
  3. */
  4. @RequestMapping("/sort")
  5. public List<Person> sort() {
  6. List<Person> people = personRepository.findAll(new Sort(Direction.ASC, "age"));
  7. return people;
  8. }

代码示例来源:origin: abixen/abixen-platform

  1. @Override
  2. public Sort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
  3. final ArrayNode node = jsonParser.getCodec().readTree(jsonParser);
  4. final Order[] orders = new Order[node.size()];
  5. int i = 0;
  6. for (JsonNode jsonNode : node) {
  7. orders[i] = new Order(Direction.valueOf(jsonNode.get("direction").asText()), jsonNode.get("property").asText());
  8. i++;
  9. }
  10. return new Sort(orders);
  11. }

代码示例来源:origin: dyc87112/spring-cloud-config-admin

  1. @Override
  2. public List<UserDto> getUsers() {
  3. List<User> userList = userRepo.findAll(new Sort(Sort.Direction.DESC, "id"));
  4. List<UserDto> userDtoList = new ArrayList<>(userList.size());
  5. userList.forEach(user -> userDtoList.add(toDto(user)));
  6. return userDtoList;
  7. }

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

  1. @Override
  2. public Sort createSort() {
  3. List<Order> orders = new ArrayList<Order>();
  4. orders.add(new Order(Direction.ASC, "organisation.id"));
  5. orders.add(new Order(Direction.ASC, "id"));
  6. Sort sort = new Sort(orders);
  7. return sort;
  8. }

代码示例来源:origin: pl.edu.icm.synat/synat-business-services-impl

  1. @Override
  2. public Sort createSort() {
  3. List<Order> orders = new ArrayList<Order>();
  4. orders.add(new Order(Direction.ASC, "ip"));
  5. orders.add(new Order(Direction.ASC, "organisation.id"));
  6. orders.add(new Order(Direction.ASC, "id"));
  7. Sort sort = new Sort(orders);
  8. return sort;
  9. }

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-repository-jpa

  1. @Override
  2. public Optional<Action> findOldestActiveActionByTarget(final String controllerId) {
  3. if (!actionRepository.activeActionExistsForControllerId(controllerId)) {
  4. return Optional.empty();
  5. }
  6. // used in favorite to findFirstByTargetAndActiveOrderByIdAsc due to
  7. // DATAJPA-841 issue.
  8. return actionRepository.findFirstByTargetControllerIdAndActive(new Sort(Direction.ASC, "id"), controllerId,
  9. true);
  10. }

代码示例来源:origin: pl.edu.icm.synat/synat-neo4j-graph-impl

  1. @Override
  2. @Transactional(value = "neo4jTransactionManager", readOnly = true)
  3. public Page<Citation> getMostCitedAuhtorByOtherAuthors(Integer pageNumber, Integer pageSize, String authorId, CitationType citationType) {
  4. Pageable pageable = new PageRequest(pageNumber, pageSize, new Sort(Direction.DESC, "count"));
  5. return citationsPageFunction.apply(contentRepository.getMostCitedAuthorsByAuthor(authorId, citationType.name(), pageable));
  6. }

代码示例来源:origin: dyc87112/spring-cloud-config-admin

  1. @Override
  2. public List<Permission> getPermission(Long userId) {
  3. if (!userService.existUser(userId)) {
  4. throw new ServiceException("用户不存在");
  5. }
  6. Sort sort = new Sort(Sort.Direction.ASC, "envId", "projectId");
  7. return permissionRepo.findAllByUserId(userId, sort);
  8. }

代码示例来源:origin: com.epam.reportportal/commons-dao

  1. @Override
  2. public List<TestItem> loadItemsHistory(List<String> uniqueIds, List<String> launchesIds) {
  3. if (CollectionUtils.isEmpty(uniqueIds) || CollectionUtils.isEmpty(launchesIds)) {
  4. return Collections.emptyList();
  5. }
  6. Query query = query(where(LAUNCH_REFERENCE).in(launchesIds).and(UNIQUE_ID).in(uniqueIds));
  7. query.with(new Sort(ASC, ID));
  8. query.limit(HISTORY_LIMIT);
  9. return mongoTemplate.find(query, TestItem.class);
  10. }

代码示例来源:origin: com.epam.reportportal/commons-dao

  1. @Override
  2. public List<TestItem> findForSpecifiedSubType(List<String> launchesIds, boolean hasChild, StatisticSubType type) {
  3. String issueField =
  4. "statistics.issueCounter." + TestItemIssueType.valueOf(type.getTypeRef()).awareStatisticsField() + "." + type.getLocator();
  5. Query query = query(where(LAUNCH_REFERENCE).in(launchesIds)).addCriteria(where(HAS_CHILD).is(hasChild))
  6. .addCriteria(where(issueField).exists(true))
  7. .with(new Sort(Sort.Direction.ASC, START_TIME));
  8. return mongoTemplate.find(query, TestItem.class);
  9. }

相关文章