microblog | 微博客
原创
访问
0
获赞
0
评论
相关推荐
暂无数据
最新文章
暂无数据
热门文章
暂无数据

解决com.github.pagehelper.PageInterceptor插件出现空指针问题

写完bug就找女朋友 2023年08月19日 21:49:53 200 15200 0
分类专栏: Java JavaWeb

在用ssm框架搬砖的时候,用到com.github.pagehelper.PageInterceptor这个分页插件,因为第一次用到,也遇到了许多问题,空指针就是其中一个,通过自己千辛万苦终于解决了。

问题截图如下:
image.png

再来看看我application.xml和mybatis.xml配置文件的一部分:
application.xml部分:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 指定mybatis全局配置文件的位置 --> <property name="configLocation" value="classpath:mybatis-config.xml"></property> <property name="dataSource" ref="pooledDataSource"></property> <!-- 指定mybatis,mapper文件的位置 --> <property name="mapperLocations" value="classpath:mapper/*.xml"></property> <!-- 注意!!!!这个插件只能在一个地方配置一次,如果再这里配置了,在mybatis-config.xml 文件里面就不要配置了,否则会出现空指针问题!!!!--> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <value> params=value1 </value> </property> </bean> </array> </property> </bean>

mybatis.xml:

<!-- 注意!!!!这个插件只能在一个地方配置一次,如果再这里配置了,在mybatis-config.xml文件里面就不要配置了,否则会出现空指针问题!!!!--> <plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor"> <!--分页参数合理化 --> <property name="reasonable" value="true"/> </plugin> </plugins>

注意一下我两个文件的其中的注释,之前出现的那个空指针问题,就是我分别在application.xml文件和mybatis.xml两个文件里面都做了配置,所以会出现空指针问题,只要把其中一个地方注释掉,这个问题就可以得到解决了。

如果你在搬砖的时候用这个插件也遇到类似的空指针问题,那么快去检查检查吧。



评论区

登录后参与交流、获取后续更新提醒

目录
暂无数据