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

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

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

Sort.toString介绍

暂无

代码示例

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

@Test
public void testDoReadFirstReadNoResults() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<>()));
  assertNull(reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(0, pageRequest.getOffset());
  assertEquals(0, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

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

@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadExhausted() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  final Object result = new Object();
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add(new Object());
  }})).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add(result);
  }})).thenReturn(new PageImpl<>(new ArrayList<>()));
  assertFalse(reader.doRead() == result);
  assertEquals(result, reader.doRead());
  assertNull(reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(2, pageRequest.getOffset());
  assertEquals(2, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

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

@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadResults() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  final Object result = new Object();
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add(result);
  }}));
  assertEquals(result, reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(0, pageRequest.getOffset());
  assertEquals(0, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

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

@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadSecondPage() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  final Object result = new Object();
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add(new Object());
  }})).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add(result);
  }}));
  assertFalse(reader.doRead() == result);
  assertEquals(result, reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(1, pageRequest.getOffset());
  assertEquals(1, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

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

@Test
@SuppressWarnings("serial")
public void testJumpToItem() throws Exception {
  reader.setPageSize(100);
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add(new Object());
  }}));
  reader.jumpToItem(485);
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(400, pageRequest.getOffset());
  assertEquals(4, pageRequest.getPageNumber());
  assertEquals(100, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

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

@Test
public void testDifferentTypes() throws Exception {
  TestRepository differentRepository = mock(TestRepository.class);
  RepositoryItemReader<String> reader = new RepositoryItemReader<>();
  sorts = new HashMap<>();
  sorts.put("id", Direction.ASC);
  reader.setRepository(differentRepository);
  reader.setPageSize(1);
  reader.setSort(sorts);
  reader.setMethodName("findFirstNames");
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  when(differentRepository.findFirstNames(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<String>(){{
    add("result");
  }}));
  assertEquals("result", reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(0, pageRequest.getOffset());
  assertEquals(0, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

代码示例来源:origin: excelsior-oss/restler

@Override
protected String getPathPart(Object[] args) {
  Sort sort = (Sort)args[0];
  return "?sort=" + sort.toString().replace(": ", ",");
}

代码示例来源:origin: top.wboost/common-web

public PageResolver(int pageNumber, int pageSize, Sort sort) {
  this.basePage = new BasePage();
  this.basePage.pageNumber = pageNumber;
  this.basePage.pageSize = pageSize;
  String[] sortAndOrder = sort.toString().split(":");
  this.basePage.sort = sortAndOrder[0].trim();
  this.basePage.order = sortAndOrder[1].trim();
}

代码示例来源:origin: com.intoverflow.booster/booster-core

/**
 * 拼排序
 *
 * @param sort
 * @return
 */
public String prepareOrder(Sort sort) {
  if (sort == null || !sort.iterator().hasNext()) {
    return "";
  }
  StringBuilder orderBy = new StringBuilder("");
  orderBy.append(" order by ");
  orderBy.append(sort.toString().replace(":", " "));
  return orderBy.toString();
}

代码示例来源:origin: excelsior-oss/restler

@Override
protected String getPathPart(Object[] args) {
  Pageable page = (Pageable) args[0];
  return "?page=" + page.getPageNumber() + "&size=" + page.getPageSize() + "&sort=" + page.getSort().toString().replace(": ", ",");
}

代码示例来源:origin: nurkiewicz/spring-data-jdbc-repository

public static String generateSelectAllWithPagination(TableDescription table, Pageable page, SqlGenerator sqlGenerator) {
    final int beginOffset = page.getPageNumber() * page.getPageSize() + 1;
    final int endOffset = beginOffset + page.getPageSize() - 1;
    String orderByPart = page.getSort() != null ? page.getSort().toString().replace(":", "") : table.getIdColumns().get(0);
    String selectAllPart = sqlGenerator.selectAll(table);
    return String.format(ROW_NUM_WRAPPER, orderByPart, selectAllPart, beginOffset, endOffset);
  }
}

代码示例来源:origin: com.nurkiewicz.jdbcrepository/jdbcrepository

public static String generateSelectAllWithPagination(TableDescription table, Pageable page, SqlGenerator sqlGenerator) {
    final int beginOffset = page.getPageNumber() * page.getPageSize() + 1;
    final int endOffset = beginOffset + page.getPageSize() - 1;
    String orderByPart = page.getSort() != null ? page.getSort().toString().replace(":", "") : table.getIdColumns().get(0);
    String selectAllPart = sqlGenerator.selectAll(table);
    return String.format(ROW_NUM_WRAPPER, orderByPart, selectAllPart, beginOffset, endOffset);
  }
}

代码示例来源:origin: stackoverflow.com

theNumberOfResults);
log.debug("query {} {} executed against lucene index: returned {} total items, {} in this page",qry.toString(),
                                                (theSort != null ? theSort.toString() : ""),
                                                scoredDocs != null ? scoredDocs.totalHits : 0,
                                                scoredDocs != null ? scoredDocs.scoreDocs.length : 0);

代码示例来源:origin: com.ecfront.dew/boot-core

default Resp<Page<E>> paging(int pageNumber, int pageSize, Sort sort) throws RuntimeException {
  logger.debug("[{}] Paging {} {} {}.", getModelClazz().getSimpleName(), pageNumber, pageSize, sort != null ? sort.toString() : "");
  Resp<Optional<Object>> preResult = prePaging();
  if (preResult.ok()) {
    return Resp.success(postPaging(getDewRepository().paging(pageNumber, pageSize, sort), preResult.getBody()));
  }
  return Resp.customFail(preResult.getCode(), preResult.getMessage());
}

代码示例来源:origin: com.ecfront.dew/boot-core

default Resp<Page<E>> pagingDisable(int pageNumber, int pageSize, Sort sort) throws RuntimeException {
  logger.debug("[{}] PagingDisable {} {} {}.", getModelClazz().getSimpleName(), pageNumber, pageSize, sort != null ? sort.toString() : "");
  Resp<Optional<Object>> preResult = prePaging();
  if (preResult.ok()) {
    return Resp.success(postPaging(getDewRepository().pagingDisable(pageNumber, pageSize, sort), preResult.getBody()));
  }
  return Resp.customFail(preResult.getCode(), preResult.getMessage());
}

代码示例来源:origin: com.ecfront.dew/boot-core

default Resp<Page<E>> pagingEnable(int pageNumber, int pageSize, Sort sort) throws RuntimeException {
  logger.debug("[{}] PagingEnable {} {} {}.", getModelClazz().getSimpleName(), pageNumber, pageSize, sort != null ? sort.toString() : "");
  Resp<Optional<Object>> preResult = prePaging();
  if (preResult.ok()) {
    return Resp.success(postPaging(getDewRepository().pagingEnable(pageNumber, pageSize, sort), preResult.getBody()));
  }
  return Resp.customFail(preResult.getCode(), preResult.getMessage());
}

相关文章