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