Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
0
 @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(","))));
   }
 }