use of com.optimus.common.mybatis.PageParam in project luntan by caoawei.
the class PageInterceptor method resolvePageParam.
private void resolvePageParam(Object handler, HttpServletRequest request) {
String $start = request.getParameter(Constant.PAGE_CONFIG_PARAM_START);
String $limit = request.getParameter(Constant.PAGE_CONFIG_PARAM_LIMIT);
int start;
int limit;
if (Utils.isEmpty($start) || Utils.isEmpty($limit)) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
PageConfig pc = handlerMethod.getMethod().getAnnotation(PageConfig.class);
start = pc.start();
limit = pc.limit();
} else {
start = Math.max(Integer.valueOf($start), 0);
limit = Math.min(Integer.valueOf($limit), Integer.MAX_VALUE);
}
PageParam pageParam = PageParam.initWithOffset(start, limit);
ThreadPageUtil.putPageParam(pageParam);
}
use of com.optimus.common.mybatis.PageParam in project luntan by caoawei.
the class DubboUtil method getPageParam.
public static PageParam getPageParam(DubboKey dubboKey) {
String val = getAttachment(dubboKey.getKey());
PageParam pageParam = Utils.fromJson(val, PageParam.class);
return pageParam;
}
use of com.optimus.common.mybatis.PageParam in project luntan by caoawei.
the class MybatisPageInterceptor method intercept.
@Override
public Object intercept(Invocation invocation) throws Throwable {
if (PageUtil.needPage() && sqlParser.isSupport(DBType.MYSQL)) {
Executor executor = (Executor) invocation.getTarget();
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
Object parameterObject = invocation.getArgs()[1];
BoundSql boundSql = ms.getBoundSql(parameterObject);
RowBounds rowBounds = (RowBounds) invocation.getArgs()[2];
ResultHandler resultHandler = (ResultHandler) invocation.getArgs()[3];
Connection connection = executor.getTransaction().getConnection();
String countSql = sqlParser.parseWithCountQuery(boundSql.getSql().trim());
BoundSql countBoundSql = copyBoundSql(ms, boundSql, countSql);
PreparedStatement ps = connection.prepareStatement(countSql);
setParameters(ps, ms, countBoundSql);
ResultSet resultSet = ps.executeQuery();
if (resultSet.next()) {
PageParam pageParam = resolvePageParam(resultSet);
PageList pageList = initPageList(pageParam);
String pageSql = sqlParser.parseWithPageQuery(boundSql.getSql().trim());
Utils.setFieldValue("sql", boundSql, pageSql);
List list = query(executor, ms, parameterObject, boundSql, rowBounds, resultHandler);
pageList.addAll(list);
return pageList;
}
resultSet.close();
connection.close();
}
return invocation.proceed();
}
use of com.optimus.common.mybatis.PageParam in project luntan by caoawei.
the class MybatisPageInterceptor method resolvePageParam.
private PageParam resolvePageParam(ResultSet resultSet) throws SQLException {
PageParam pageParam = PageUtil.getPageParam();
int count = resultSet.getInt(1);
int pageNumber = (count / pageParam.getLimit()) + 1;
pageParam.setTotalCount(count);
pageParam.setPageNumber(pageNumber);
return pageParam;
}
use of com.optimus.common.mybatis.PageParam in project luntan by caoawei.
the class MySqlSqlParser method parseWithPageQuery.
@Override
public String parseWithPageQuery(String srcSql) {
PageParam pageParam = ThreadPageUtil.getPageParam();
StringBuilder newSql = new StringBuilder(srcSql);
return newSql.append(" limit ").append(pageParam.getStart()).append(",").append(pageParam.getLimit()).toString();
}
Aggregations