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

版权声明:转载请标注来源: https://blog.csdn.net/qq_37844454/article/details/85315365

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

问题截图如下:

再来看看我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两个文件里面都做了配置,所以会出现空指针问题,只要把其中一个地方注释掉,这个问题就可以得到解决了。

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

猜你喜欢

转载自blog.csdn.net/qq_37844454/article/details/85315365