@RequestMapping(path = "/get/page", method = GET)
 @ResponseStatus(value = OK)
 @JsonView(DiscountCardView.BasicLevel.class)
 public Page<DiscountCard> getAll(
     @RequestParam(defaultValue = "0", required = false) int page,
     @RequestParam(defaultValue = "15", required = false) int size,
     @RequestParam(defaultValue = "DESC", required = false) String direction,
     @RequestParam(defaultValue = "createdDate", required = false) String property) {
   return service.getAll(
       new PageRequest(page, size, new Sort(Sort.Direction.valueOf(direction), property)));
 }
 /**
  * Creates an index on the desired field in the target collection.
  *
  * @param field
  * @param direction
  * @param isUnique
  * @param isSparse
  */
 public void createIndex(
     String field, Sort.Direction direction, boolean isUnique, boolean isSparse) {
   Integer dir = direction.equals(Sort.Direction.ASC) ? 1 : -1;
   DBObject index = new BasicDBObject(field, dir);
   DBObject options = new BasicDBObject();
   if (isSparse) options.put("sparse", true);
   if (isUnique) options.put("unique", true);
   DBCollection collection =
       mongoOperations.getCollection(mongoOperations.getCollectionName(model));
   collection.createIndex(index, options);
 }
 @RequestMapping(path = "/owner/page", method = GET, produces = APPLICATION_JSON_VALUE)
 @ResponseStatus(OK)
 @JsonView(DiscountCardView.BasicLevel.class)
 public Page<DiscountCard> getAuthenticatedPersonDiscountCards(
     @RequestParam(defaultValue = "0", required = false) int page,
     @RequestParam(defaultValue = "15", required = false) int size,
     @RequestParam(defaultValue = "DESC", required = false) String direction,
     @RequestParam(defaultValue = "createdDate", required = false) String property) {
   return service.getAuthenticatedPersonDiscountCards(
       new PageRequest(page, size, new Sort(Sort.Direction.valueOf(direction), property)));
 }
Esempio n. 4
0
  public List<FileEntity> listFilesByParent(Long parent, String[]... sortProperties) {

    List<Sort.Order> orders = new ArrayList<Sort.Order>();
    for (String[] sp : sortProperties) {
      orders.add(new Sort.Order(Sort.Direction.fromString(sp[1]), sp[0]));
    }
    Sort sort = new Sort(orders);

    if (parent == null) {
      return fileRepository.findByParent(null, sort);
    } else {
      return fileRepository.findByParent(new FileEntity(parent), sort);
    }
  }
 @RequestMapping(value = "roles", method = RequestMethod.POST)
 @ResponseBody
 public Map<String, Object> roles(
     @ModelAttribute RoleDomain roleDomain, BindingResult bindingResult) {
   Pageable pageable =
       new PageRequest(
           roleDomain.getPage(),
           roleDomain.getPageSize(),
           new Sort(Sort.Direction.fromString(roleDomain.getSortDir()), roleDomain.getSortCol()));
   Page<OsRole> tmp = iRoleService.findAll(pageable);
   Map<String, Object> map = new HashMap<>(5);
   map.put("success", true);
   map.put("msg", !tmp.getContent().isEmpty() ? "" : "记录不存在");
   map.put("data", tmp.getContent());
   map.put("iTotalRecords", tmp.getTotalElements());
   map.put("iTotalDisplayRecords", tmp.getTotalElements());
   return map;
 }
 private Sort parseParameterIntoSort(String[] directionParameter) {
   List<Order> allOrders = new ArrayList<Sort.Order>();
   for (String part : directionParameter) {
     try {
       List<SortRequest> allSortRequests =
           objectMapper.readValue(part, new TypeReference<List<SortRequest>>() {});
       for (SortRequest sortRequest : allSortRequests) {
         allOrders.add(
             new Order(
                 Sort.Direction.fromString(sortRequest.getDirection()),
                 sortRequest.getProperty()));
       }
     } catch (IOException ex) {
       Logger.getLogger(ExtSortHandlerMethodArgumentResolver.class.getName())
           .log(Level.SEVERE, null, ex);
     }
   }
   return allOrders.isEmpty() ? null : new Sort(allOrders);
 }
 /** {@inheritDoc} */
 @Override
 public Page<T> findPaginated(
     @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
     @RequestParam(value = "size", required = false, defaultValue = "10") Integer size,
     @RequestParam(value = "direction", required = false, defaultValue = "") String direction,
     @RequestParam(value = "properties", required = false) String properties) {
   Assert.isTrue(page > 0, "Page index must be greater than 0");
   Assert.isTrue(
       direction.isEmpty()
           || direction.equalsIgnoreCase(Sort.Direction.ASC.toString())
           || direction.equalsIgnoreCase(Sort.Direction.DESC.toString()),
       "Direction should be ASC or DESC");
   if (direction.isEmpty()) {
     return this.service.findAll(new PageRequest(page - 1, size));
   } else {
     Assert.notNull(properties);
     return this.service.findAll(
         new PageRequest(
             page - 1,
             size,
             new Sort(Sort.Direction.fromString(direction.toUpperCase()), properties.split(","))));
   }
 }