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;
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations