本文整理匯總了Java中org.springframework.data.domain.Sort.Direction類的典型用法代碼示例。如果您正苦於以下問題:Java Direction類的具體用法?Java Direction怎麽用?Java Direction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Direction類屬於org.springframework.data.domain.Sort包,在下文中一共展示了Direction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldRetrieveBooksPerPublisherWithTitles
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* Get number of books that were published by the particular publisher with their titles.
*/
@Test
public void shouldRetrieveBooksPerPublisherWithTitles() {
Aggregation aggregation = newAggregation( //
group("volumeInfo.publisher") //
.count().as("count") //
.addToSet("volumeInfo.title").as("titles"), //
sort(Direction.DESC, "count"), //
project("count", "titles").and("_id").as("publisher"));
AggregationResults<BooksPerPublisher> result = operations.aggregate(aggregation, "books", BooksPerPublisher.class);
BooksPerPublisher booksPerPublisher = result.getMappedResults().get(0);
assertThat(booksPerPublisher.getPublisher()).isEqualTo("Apress");
assertThat(booksPerPublisher.getCount()).isEqualTo(26);
assertThat(booksPerPublisher.getTitles()).contains("Expert Spring MVC and Web Flow", "Pro Spring Boot");
}
示例2: saveAndBroadcast
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
public void saveAndBroadcast(InboundSmsMessage smsMessage){
log.info("Inbound message received {}", smsMessage);
inboundSmsMessageRepository.save(smsMessage);
Pageable page = (Pageable) PageRequest.of(0, 1, Direction.DESC, "date");
List<Conversation> conversations = conversationRepository.findByPhoneNumber(smsMessage.getMsisdn(), page);
if( ! conversations.isEmpty()){
Conversation conversation = conversations.get(0);
Optional<Participant> user = conversation.findParticipantByPhone(smsMessage.getMsisdn());
if(user.isPresent()){
ConversationMessage conversationMessage = createConversationMessage(smsMessage, conversation, user.get());
broadcastMessage(conversationMessage);
}else{
log.warn("No participant found associated with {} in {}", smsMessage.getMsisdn(), conversation.getId());
}
}else{
log.warn("No conversation found associated with {}", smsMessage.getMsisdn());
}
}
示例3: getSeveral
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
@RequestMapping(method=GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Get overviews of stocks", notes = "Return a page of stock-overviews")
public PagedResources<StockProductResource> getSeveral(
@Or({
@Spec(params="cn", path="id", spec=LikeIgnoreCase.class),
@Spec(params="cn", path="name", spec=LikeIgnoreCase.class)}
) @ApiIgnore Specification<StockProduct> spec,
@ApiParam(value="Exchange ID") @RequestParam(value="exchange", required=false) String exchangeId,
@ApiParam(value="Index ID") @RequestParam(value="index", required=false) String indexId,
@ApiParam(value="Market ID") @RequestParam(value="market", required=false) MarketId marketId,
@ApiParam(value="Starts with filter") @RequestParam(value="sw", defaultValue="", required=false) String startWith,
@ApiParam(value="Contains filter") @RequestParam(value="cn", defaultValue="", required=false) String contain,
@ApiIgnore @PageableDefault(size=10, page=0, sort={"name"}, direction=Direction.ASC) Pageable pageable){
return pagedAssembler.toResource(stockProductService.gather(indexId, exchangeId, marketId, startWith, spec, pageable), assembler);
}
示例4: getPageable
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* Creates a 'LIMIT .. OFFSET .. ORDER BY ..' clause for the given
* {@link DataTablesInput}.
*
* @param input
* the {@link DataTablesInput} mapped from the Ajax request
* @return a {@link Pageable}, must not be {@literal null}.
*/
@Transactional
private Pageable getPageable(DataTablesInput input) {
List<Order> orders = new ArrayList<Order>();
for (OrderParameter order : input.getOrder()) {
log.debug("order column: " + order.getColumn() + "");
ColumnParameter column = input.getColumns().get(order.getColumn());
if (column.getOrderable()) {
String sortColumn = column.getData();
Direction sortDirection = Direction.fromString(order.getDir());
orders.add(new Order(sortDirection, sortColumn));
}
}
Sort sort = orders.isEmpty() ? null : new Sort(orders);
if (input.getLength() == -1) {
input.setStart(0);
input.setLength(Integer.MAX_VALUE);
}
return new PageRequest(input.getStart() / input.getLength(), input.getLength(), sort);
}
示例5: findAll
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
@Override
public Page<T> findAll(final Set<T> groups, final String criteria, final Pageable pageable, final Map<String, Comparator<T>> customComparators) {
// Create the set with the right comparator
final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator());
orders.add(DEFAULT_ORDER);
final Sort.Order order = orders.get(0);
Comparator<T> comparator = customComparators.get(order.getProperty());
if (order.getDirection() == Direction.DESC) {
comparator = Collections.reverseOrder(comparator);
}
final Set<T> result = new TreeSet<>(comparator);
// Filter the groups, filtering by the criteria
addFilteredByPattern(groups, criteria, result);
// Apply in-memory pagination
return inMemoryPagination.newPage(result, pageable);
}
示例6: findAll
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* 方法名 : findAll
* 功 能 : TODO(這裏用一句話描述這個方法的作用)
* 參 數 : @return
* 參 考 : @see tk.ainiyue.admin.roles.service.SysRolesService#findAll()
* 作 者 : Tenghui.Wang
*/
@Override
public Page<SysSeedInfo> findAll(int pageNumber, int pageSize, String searchText) {
Sort sort = new Sort(new Order(Direction.DESC, "seedName"));
PageRequest request = this.buildPageRequest(pageNumber, pageSize, sort);
Page<SysSeedInfo> sourceCodes = null;
if (searchText == null || "".equals(searchText)) {
sourceCodes = sysSeedDao.findAll(request);
} else {
SysSeedInfo info = new SysSeedInfo();
info.setSeedName(searchText);
Example<SysSeedInfo> example = Example.of(info);
sourceCodes = sysSeedDao.findAll(example, request);
}
return sourceCodes;
}
示例7: articleList
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
@RequestMapping("articleList")
public PageableResultJson articleList(@RequestParam(value = "page") Integer page, Long id, String title) {
PageableResultJson tableJson = new PageableResultJson();
Sort sort = new Sort(Direction.DESC, "id");
Pageable pageable = new PageRequest(page, PageableResultJson.PAGE_SIZE, sort);
Page<Article> pageData = null;
if (StringUtils.isEmpty(title)) {
pageData = articleDao.findArticleByAuthorId(id, pageable);
} else {
pageData = articleDao.findArticleByAuthorIdAndTitleLike(id, title, pageable);
}
tableJson.setData(pageData.getContent());
tableJson.setPageSize(PageableResultJson.PAGE_SIZE);
tableJson.setTotalPageNumber(pageData.getTotalPages());
return tableJson;
}
示例8: getAllPosts
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
@GetMapping()
// @ApiOperation(nickname = "get-all-posts", value = "Get all posts")
// @ApiResponses(
// value = {
// @ApiResponse(code = 200, message = "return all posts by page")
// }
// )
@JsonView(View.Summary.class)
public ResponseEntity<Page<Post>> getAllPosts(
@RequestParam(value = "q", required = false) String keyword, //
@RequestParam(value = "status", required = false) Post.Status status, //
@PageableDefault(page = 0, size = 10, sort = "createdDate", direction = Direction.DESC) Pageable page) {
log.debug("get all posts of [email protected]" + keyword + ", status @" + status + ", [email protected]" + page);
Page<Post> posts = this.postRepository.findAll(PostSpecifications.filterByKeywordAndStatus(keyword, status), page);
return new ResponseEntity<>(posts, HttpStatus.OK);
}
示例9: getOrdes
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
public static <T> List<Order> getOrdes(String orderBy) {
if (StringUtils.isEmpty(orderBy)) {
return Collections.emptyList();
}
String[] groups = orderBy.trim().split(",");
List<Order> orders = new ArrayList<Order>(groups.length);
for (String group : groups) {
boolean ascending = true;
String[] array = group.split("\\s", 2);
String property = array[0];
if (array.length > 1) {
ascending ="asc".equalsIgnoreCase(array[0]);;
}
Order order = new Order(ascending ? Direction.ASC : Direction.DESC, property);
orders.add(order);
}
return orders;
}
示例10: shouldRetrieveBooksPerPublisher
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* Get number of books that were published by the particular publisher.
*/
@Test
public void shouldRetrieveBooksPerPublisher() {
Aggregation aggregation = newAggregation( //
group("volumeInfo.publisher") //
.count().as("count"), //
sort(Direction.DESC, "count"), //
project("count").and("_id").as("publisher"));
AggregationResults<BooksPerPublisher> result = operations.aggregate(aggregation, "books", BooksPerPublisher.class);
assertThat(result).hasSize(27);
assertThat(result).extracting("publisher").containsSequence("Apress", "Packt Publishing Ltd");
assertThat(result).extracting("count").containsSequence(26, 22, 11);
}
示例11: shouldRetrieveDataRelatedBooks
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* Filter for Data-related books in their title and output the title and authors.
*/
@Test
public void shouldRetrieveDataRelatedBooks() {
Aggregation aggregation = newAggregation( //
match(Criteria.where("volumeInfo.title").regex("data", "i")), //
replaceRoot("volumeInfo"), //
project("title", "authors"), //
sort(Direction.ASC, "title"));
AggregationResults<BookAndAuthors> result = operations.aggregate(aggregation, "books", BookAndAuthors.class);
BookAndAuthors bookAndAuthors = result.getMappedResults().get(1);
assertThat(bookAndAuthors.getTitle()).isEqualTo("Spring Data");
assertThat(bookAndAuthors.getAuthors()).contains("Mark Pollack", "Oliver Gierke", "Thomas Risberg", "Jon Brisbin",
"Michael Hunger");
}
示例12: shouldRetrievePagesPerAuthor
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* Retrieve the number of pages per author (and divide the number of pages by the number of authors).
*/
@Test
public void shouldRetrievePagesPerAuthor() {
Aggregation aggregation = newAggregation( //
match(Criteria.where("volumeInfo.authors").exists(true)), //
replaceRoot("volumeInfo"), //
project("authors", "pageCount") //
.and(ArithmeticOperators.valueOf("pageCount") //
.divideBy(ArrayOperators.arrayOf("authors").length()))
.as("pagesPerAuthor"),
unwind("authors"), //
group("authors") //
.sum("pageCount").as("totalPageCount") //
.sum("pagesPerAuthor").as("approxWritten"), //
sort(Direction.DESC, "totalPageCount"));
AggregationResults<PagesPerAuthor> result = operations.aggregate(aggregation, "books", PagesPerAuthor.class);
PagesPerAuthor pagesPerAuthor = result.getMappedResults().get(0);
assertThat(pagesPerAuthor.getAuthor()).isEqualTo("Josh Long");
assertThat(pagesPerAuthor.getTotalPageCount()).isEqualTo(1892);
assertThat(pagesPerAuthor.getApproxWritten()).isEqualTo(573);
}
示例13: centerfans
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
@RequestMapping("/center/fans")
@Menu(type = "apps" , subtype = "user" , name="fans" , access = false)
public ModelAndView centerfans(HttpServletRequest request , HttpServletResponse response, @Valid String orgi, @Valid String q) {
ModelAndView view = request(super.createAppsTempletResponse("/apps/user/centerfans")) ;
String userid = super.getUser(request).getId() ;
Pageable page = new PageRequest(super.getP(request), super.getPs(request), new Sort(Direction.DESC, "createtime")) ;
Page<Fans> fansList = fansRes.findByUser(userid, page) ;
List<String> userids = new ArrayList<String>();
for(Fans fan : fansList){
userids.add(fan.getCreater()) ;
}
if(userids.size()>0){
view.addObject("fansList",new PageImpl<User>(userRes.findAll(userids), page, fansList.getTotalElements()) ) ;
}
return view;
}
示例14: centerfollows
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
@RequestMapping("/center/follows")
@Menu(type = "apps" , subtype = "user" , name="follows" , access = false)
public ModelAndView centerfollows(HttpServletRequest request , HttpServletResponse response, @Valid String orgi, @Valid String q) {
ModelAndView view = request(super.createAppsTempletResponse("/apps/user/centerfollows")) ;
String userid = super.getUser(request).getId() ;
Pageable page = new PageRequest(super.getP(request), super.getPs(request), new Sort(Direction.DESC, "createtime")) ;
Page<Fans> fansList = fansRes.findByCreater(userid, page) ;
List<String> userids = new ArrayList<String>();
for(Fans fan : fansList){
userids.add(fan.getUser()) ;
}
if(userids.size()>0){
view.addObject("fansList",new PageImpl<User>(userRes.findAll(userids), page, fansList.getTotalElements()) ) ;
}
return view;
}
示例15: listarPorFuncionarioId
import org.springframework.data.domain.Sort.Direction; //導入依賴的package包/類
/**
* Retorna a listagem de lançamentos de um funcionário.
*
* @param funcionarioId
* @return ResponseEntity<Response<LancamentoDto>>
*/
@GetMapping(value = "/funcionario/{funcionarioId}")
public ResponseEntity<Response<Page<LancamentoDto>>> listarPorFuncionarioId(
@PathVariable("funcionarioId") Long funcionarioId,
@RequestParam(value = "pag", defaultValue = "0") int pag,
@RequestParam(value = "ord", defaultValue = "id") String ord,
@RequestParam(value = "dir", defaultValue = "DESC") String dir) {
log.info("Buscando lançamentos por ID do funcionário: {}, página: {}", funcionarioId, pag);
Response<Page<LancamentoDto>> response = new Response<Page<LancamentoDto>>();
PageRequest pageRequest = new PageRequest(pag, this.qtdPorPagina, Direction.valueOf(dir), ord);
Page<Lancamento> lancamentos = this.lancamentoService.buscarPorFuncionarioId(funcionarioId, pageRequest);
Page<LancamentoDto> lancamentosDto = lancamentos.map(lancamento -> this.converterLancamentoDto(lancamento));
response.setData(lancamentosDto);
return ResponseEntity.ok(response);
}