Search in sources :

Example 1 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project RuoYi-Flowable-Plus by KonBAI-Q.

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 2 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project solon by noear.

the class PaginationInnerInterceptor method beforeQuery.

@Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
    IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
    if (null == page) {
        return;
    }
    // 处理 orderBy 拼接
    boolean addOrdered = false;
    String buildSql = boundSql.getSql();
    List<OrderItem> orders = page.orders();
    if (CollectionUtils.isNotEmpty(orders)) {
        addOrdered = true;
        buildSql = this.concatOrderBy(buildSql, orders);
    }
    // size 小于 0 且不限制返回值则不构造分页sql
    Long _limit = page.maxLimit() != null ? page.maxLimit() : maxLimit;
    if (page.getSize() < 0 && null == _limit) {
        if (addOrdered) {
            PluginUtils.mpBoundSql(boundSql).sql(buildSql);
        }
        return;
    }
    handlerLimit(page, _limit);
    IDialect dialect = findIDialect(executor);
    final Configuration configuration = ms.getConfiguration();
    DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), page.getSize());
    PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
    List<ParameterMapping> mappings = mpBoundSql.parameterMappings();
    Map<String, Object> additionalParameter = mpBoundSql.additionalParameters();
    model.consumers(mappings, configuration, additionalParameter);
    mpBoundSql.sql(model.getDialectSql());
    mpBoundSql.parameterMappings(mappings);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) IDialect(com.baomidou.mybatisplus.solon.plugins.pagination.dialects.IDialect) DialectModel(com.baomidou.mybatisplus.solon.plugins.pagination.DialectModel) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem)

Example 3 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project pig by pig-mesh.

the class SqlFilterArgumentResolver 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)

Example 4 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project waynboot-mall by wayn111.

the class BaseController method getPage.

/**
 * 获取分页对象
 * @param <T>
 * @return 返回分页对象
 */
protected <T> Page<T> getPage() {
    // 设置通用分页
    try {
        Integer pageNumber = ServletUtils.getParameterToInt(Constants.PAGE_NUMBER);
        Integer pageSize = ServletUtils.getParameterToInt(Constants.PAGE_SIZE);
        String sortName = ServletUtils.getParameter(Constants.SORT_NAME);
        String sortOrder = ServletUtils.getParameter(Constants.SORT_ORDER);
        Page<T> tPage = new Page<>(pageNumber, pageSize);
        if (StringUtils.isNotEmpty(sortName)) {
            String[] split = sortName.split(",");
            for (String s : split) {
                OrderItem orderItem = new OrderItem();
                orderItem.setColumn(s.replaceAll("[A-Z]", "_$0").toLowerCase());
                orderItem.setAsc(sortOrder == null || !sortOrder.startsWith(Constants.ORDER_DESC));
                tPage.addOrder(orderItem);
            }
        }
        return tPage;
    } catch (Exception e) {
        // log.error(e.getMessage(), e);
        return getPage(1, 10);
    }
}
Also used : OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage)

Example 5 with OrderItem

use of com.baomidou.mybatisplus.core.metadata.OrderItem in project forum by saysky.

the class PageUtil method convertPageVo.

/**
 * 设计缺陷,前端无法获取mybatis-plus的分页page中的pages,所以自己封装一个PageVO
 * 同时将分页信息塞到PageVo中
 *
 * @param page mybatis-plus分页类
 * @return
 */
public static PageVo convertPageVo(Page page) {
    PageVo pageVo = new PageVo();
    pageVo.setSize(page.getSize());
    pageVo.setTotal(page.getTotal());
    pageVo.setCurrent(page.getCurrent());
    pageVo.setPages(page.getPages());
    List<OrderItem> orderItems = page.getOrders();
    if (orderItems != null && orderItems.size() > 0) {
        pageVo.setSort(orderItems.get(0).getColumn());
        pageVo.setOrder(orderItems.get(0).isAsc() ? "asc" : "desc");
    }
    return pageVo;
}
Also used : PageVo(com.example.forum.vo.PageVo) OrderItem(com.baomidou.mybatisplus.core.metadata.OrderItem)

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