Search in sources :

Example 1 with PageParam

use of com.hccake.ballcat.common.model.domain.PageParam 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 2 with PageParam

use of com.hccake.ballcat.common.model.domain.PageParam in project ballcat by ballcat-projects.

the class PageParamArgumentResolver 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) throws Exception {
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    String current = request.getParameter("current");
    String size = request.getParameter("size");
    String sortFields = request.getParameter("sortFields");
    String sortOrders = request.getParameter("sortOrders");
    PageParam pageParam;
    try {
        pageParam = (PageParam) parameter.getParameterType().newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        pageParam = new PageParam();
    }
    if (StrUtil.isNotBlank(current)) {
        pageParam.setCurrent(Long.parseLong(current));
    }
    if (StrUtil.isNotBlank(size)) {
        pageParam.setSize(Long.parseLong(size));
    }
    List<PageParam.Sort> sorts = getOrderItems(sortFields, sortOrders);
    pageParam.setSorts(sorts);
    paramValidate(parameter, mavContainer, webRequest, binderFactory, pageParam);
    return pageParam;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageParam(com.hccake.ballcat.common.model.domain.PageParam)

Aggregations

PageParam (com.hccake.ballcat.common.model.domain.PageParam)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 OrderItem (com.baomidou.mybatisplus.core.metadata.OrderItem)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1