if (parameterObject == null) {
//throw new NullPointerException("boundSql.getParameterObject() is null!");
return ivk.proceed();
} else {
PageView pageView = null;
if (parameterObject instanceof PageView) { // 参数就是Pages实体
pageView = (PageView) parameterObject;
} else if (parameterObject instanceof Map) {
for (Entry entry : (Set<Entry>) ((Map) parameterObject)
.entrySet()) {
if (entry.getValue() instanceof PageView) {
pageView = (PageView) entry.getValue();
break;
}
}
} else { // 参数为某个实体,该实体拥有Pages属性
pageView = ReflectHelper.getValueByFieldType(
parameterObject, PageView.class);
if (pageView == null) {
return ivk.proceed();
}
}
String sql = boundSql.getSql();
PreparedStatement countStmt = null;
ResultSet rs = null;
try {
Connection connection = (Connection) ivk.getArgs()[0];
String countSql = "select count(1) from (" + sql
+ ") tmp_count"; // 记录统计
countStmt = connection.prepareStatement(countSql);
ReflectHelper.setValueByFieldName(boundSql, "sql",
countSql);
DefaultParameterHandler parameterHandler = new DefaultParameterHandler(
mappedStatement, parameterObject, boundSql);
parameterHandler.setParameters(countStmt);
rs = countStmt.executeQuery();
int count = 0;
if (rs.next()) {
count = ((Number) rs.getObject(1)).intValue();
}
pageView.setRowCount(count);
} finally {
try {
rs.close();
} catch (Exception e) {
}