分页插件pageHelper的使用:
1.在Pom.xml中导包
2.在ApplicationCntext.xml中把架包告诉给SqlSessionfactory。
3.在Service中指定 page和 size
4.Controller 把得到的结果封装到 PageInfo中在进行使用ModelAndView返回
需要使用前需要配置文件
1、pom.xml,写在中
2、applicationContext.xml
<!--3、配置sqlSessionFactory对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!--扫描dao层包 使用别名-->
<property name="typeAliasesPackage" value="com.gm.dao"/>
<!--配合加载映射文件 *mapper.xml-->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
<!--分页配置-->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<props>
<prop key="helperDialect"></prop>
<prop key="reasonable"></prop>
</props>
</property>
</bean>
</array>
</property>
1、全部查询功能中应用,老规矩先写dao接口,其次是mapper(本次操做mapper无需额外变动)
2、service接口层
3、service业务逻辑层
4、controller层,
@RequestParam(defaultValue=“1”)Integer page,//默认页数为1,
@RequestParam(defaultValue=“5”) Integer size//默认一页出现5个数据,
PageInfo中含有List存储方式所以可以直接放入list类型数据
5、user-list.xml页面