Search in sources :

Example 6 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project video-spider by zc-libre.

the class PageUtil method getOrders.

public static <T> List<Sort.Order> getOrders(PageDTO<T> page) {
    List<OrderItem> orderItems = page.getOrders();
    if (CollectionUtil.isEmpty(orderItems)) {
        return Collections.emptyList();
    }
    List<Sort.Order> orders = Lists.newArrayList();
    for (OrderItem order : orderItems) {
        if (StringUtil.isNotBlank(order.getColumn())) {
            orders.add(new Sort.Order(getDirection(order.isAsc()), order.getColumn()));
        }
    }
    return orders;
}
Also used : Order(org.springframework.data.elasticsearch.core.query.Order) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Sort(org.springframework.data.domain.Sort)

Example 7 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project ox-data-cloud by ox-data.

the class BaseServiceImpl method getPageQuery.

protected Page<T> getPageQuery(PageRequest pageParam) {
    Page<T> page = new Page<>(pageParam.getPage(), pageParam.getPerPage());
    if (pageParam.getSort() != null) {
        List<OrderItem> orderItems = new ArrayList<>();
        for (String sortProperty : pageParam.getSort()) {
            String sortType = "asc";
            if (sortProperty.contains(",")) {
                String[] sortArray = StringUtils.split(sortProperty, ",");
                if (sortArray.length >= 1) {
                    sortType = sortArray[1];
                }
                OrderItem orderItem = new OrderItem(sortArray[0], "asc".equals(sortType));
                orderItems.add(orderItem);
            }
        }
        page.addOrder(orderItems);
    }
    return page;
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 8 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project ballcat by ballcat-projects.

the class PageUtil method prodPage.

/**
 * 根据 PageParam 生成一个 IPage 实例
 * @param pageParam 分页参数
 * @param <V> 返回的 Record 对象
 * @return IPage<V>
 */
public static <V> IPage<V> prodPage(PageParam pageParam) {
    Page<V> page = new Page<>(pageParam.getCurrent(), pageParam.getSize());
    List<PageParam.Sort> sorts = pageParam.getSorts();
    for (PageParam.Sort sort : sorts) {
        OrderItem orderItem = sort.isAsc() ? OrderItem.asc(sort.getField()) : OrderItem.desc(sort.getField());
        page.addOrder(orderItem);
    }
    return page;
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) PageParam(com.hccake.ballcat.common.model.domain.PageParam)

Example 9 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project RuoYi-Vue-Plus by JavaLionLi.

the class PageQuery method build.

public <T> Page<T> build() {
    Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);
    Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
    if (pageNum <= 0) {
        pageNum = DEFAULT_PAGE_NUM;
    }
    Page<T> page = new Page<>(pageNum, pageSize);
    OrderItem orderItem = buildOrderItem();
    if (ObjectUtil.isNotNull(orderItem)) {
        page.addOrder(orderItem);
    }
    return page;
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 10 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project XHuiCloud by sindaZeng.

the class SqlFilterResolver method resolveArgument.

/**
 * @param parameter 入参集合
 * @param mavContainer model 和 view
 * @param webRequest web相关
 * @param binderFactory 入参解析
 * @return 检查后新的page对象
 * <p>
 * page 只支持查询 GET .如需解析POST获取请求报文体处理
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    String[] ascs = request.getParameterValues("ascs");
    String[] descs = request.getParameterValues("descs");
    String current = request.getParameter("current");
    String size = request.getParameter("size");
    Page page = new Page();
    if (StrUtil.isNotBlank(current)) {
        page.setCurrent(Long.parseLong(current));
    }
    if (StrUtil.isNotBlank(size)) {
        page.setSize(Long.parseLong(size));
    }
    List<OrderItem> orderItemList = new ArrayList<>();
    Optional.ofNullable(ascs).ifPresent(s -> orderItemList.addAll(Arrays.stream(s).filter(sqlInjectPredicate()).map(OrderItem::asc).collect(Collectors.toList())));
    Optional.ofNullable(descs).ifPresent(s -> orderItemList.addAll(Arrays.stream(s).filter(sqlInjectPredicate()).map(OrderItem::desc).collect(Collectors.toList())));
    page.addOrder(orderItemList);
    return page;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Aggregations

OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)23 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)12 ArrayList (java.util.ArrayList)7 IPage (com.baomidou.mybatisplus.core.metadata.IPage)6 List (java.util.List)4 Collectors (java.util.stream.Collectors)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Map (java.util.Map)2 Sort (org.springframework.data.domain.Sort)2 OrderQueryParam (co.yixiang.common.web.param.OrderQueryParam)1 DbType (com.baomidou.mybatisplus.annotation.DbType)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 DefaultIdentifierGenerator (com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator)1 IdentifierGenerator (com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator)1 TableInfo (com.baomidou.mybatisplus.core.metadata.TableInfo)1 TableInfoHelper (com.baomidou.mybatisplus.core.metadata.TableInfoHelper)1 CollectionUtils (com.baomidou.mybatisplus.core.toolkit.CollectionUtils)1 StringUtils (com.baomidou.mybatisplus.core.toolkit.StringUtils)1 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)1 IDialect (com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect)1