spring配置:
<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref=dataSource />
<property name="configLocation" value="classpath:mapper/sqlMapConfig.xml" />
<property name="plugins">
<array>
<bean class="cn.px.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
</value>
</property>
</bean>
</array>
</property>
</bean>
代码实现:
controller获取分页参数:
/**
* 获取Http请求
*
* @return
*/
public HttpServletRequest getHttpServletRequest() {
ServletRequestAttributes attr =
(ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
return attr.getRequest();
}
pageNum= request.getParameter("page");
pageSize= request.getParameter("rows");
Dao层调用查询前先加上这行代码
PageHelper.startPage(pageNum, pageSize, false, true, true);