1.业务场景
使用easyPoi导出复杂列头,多级表头以及复杂数据以及多sheet表时,解决多个sheet表不同的数据注入时,发现自己自定义的分页没起作用,而且将自己的SQL语句的返回结果改为了COUNT(0)。并且在sql语句之后自动拼接LIMIT并赋值。
2.解决过程
1.将mybatis的日志打印出来,并开启debugger进行跟代码
2.响应的sql执行中的sql语句并不是我自己的语句,感觉是XML中的sql的一对多映射有问题,使用的是
<collection property="theStudentScoreVoList"ofType="evaluationRecord.TheStudentScoreVo">
<result column="repose" property="repose"/>
</collection>
这个是没有问题的
3.然后开始查看xml中的分页的语句
<if test="end!=null and ''!=end">
<if test="start!=null and ''!= start">
LIMIT ${start},${end}
</if>
<if test="start==null and ''== start">
LIMIT #{end}
</if>
</if>
这里注意一下,我原先给的参数是pageSize和pageNum
这里注意一下,我原先给的参数是pageSize和pageNum
这里注意一下,我原先给的参数是pageSize和pageNum
4.这里也没有问题,然后去解决为什么执行中会对我自己的sql进行了修改
然后百度一下是这样说的 :
需要清理一下之前设置过的Page缓存,调用PgageHelper.clearPage()清理一下page缓存即可
但是我也这样做了 并没有任何的效果
5.然后 我跟PgageHelper的源码,发现他的属性中
private PageParams pageParams;
private PageAutoDialect autoDialect;
private PageBoundSqlInterceptors pageBoundSqlInterceptors;
中的PageParams对象的属性中有一个返回page对象的
public Page getPage(Object parameterObject, RowBounds rowBounds) {
Page page = PageHelper.getLocalPage();
if (page == null) {
if (rowBounds != RowBounds.DEFAULT) {
if (this.offsetAsPageNum) {
page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), this.rowBoundsWithCount);
} else {
page = new Page(new int[]{rowBounds.getOffset(), rowBounds.getLimit()}, this.rowBoundsWithCount);
page.setReasonable(false);
}
if (rowBounds instanceof PageRowBounds) {
PageRowBounds pageRowBounds = (PageRowBounds)rowBounds;
page.setCount(pageRowBounds.getCount() == null || pageRowBounds.getCount());
}
} else if (parameterObject instanceof IPage || this.supportMethodsArguments) {
try {
page = PageObjectUtil.getPageFromObject(parameterObject, false);
} catch (Exception var5) {
return null;
}
}
if (page == null) {
return null;
}
PageHelper.setLocalPage(page);
}
if (page.getReasonable() == null) {
page.setReasonable(this.reasonable);
}
if (page.getPageSizeZero() == null) {
page.setPageSizeZero(this.pageSizeZero);
}
return page;
}
import com.github.pagehelper.IPage;
使用 这个page对象是否属于是IPage接口类型,但是在IPage接口中的方法内容
public interface IPage {
Integer getPageNum();
Integer getPageSize();
String getOrderBy();
}
到这里的时候才知道可能是因为我的参数的命名造成的,但是具体的原因还请大佬研究一下告诉我
参数是pageSize和pageNum
P:
可能是因为是Ipage类似拦截器的功能,识别到的参数信息
此时执行对应xml中配置的select查询语句时会先执行一个select count …(你配置的表及条件),若有数据就会再执行一次select …(你配置的列、表以及条件) limit …;分页查询成功时可以看下控制台打出的sql语句。
所以 我最后跟换了参数名称之后,再次查询数据的时候好了