mybatis分页插件

Bertha 。 2022-09-30 12:54 430阅读 0赞

spring配置:

  1. <bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  2. <property name="dataSource" ref=dataSource />
  3. <property name="configLocation" value="classpath:mapper/sqlMapConfig.xml" />
  4. <property name="plugins">
  5. <array>
  6. <bean class="cn.px.pagehelper.PageHelper">
  7. <property name="properties">
  8. <value>
  9. dialect=mysql
  10. </value>
  11. </property>
  12. </bean>
  13. </array>
  14. </property>
  15. </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);

发表评论

表情:
评论列表 (有 0 条评论,430人围观)

还没有评论,来说两句吧...

相关阅读

    相关 mybatis

    使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化。缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.

    相关 Mybatis

    1.        Mybatis分页插件 \- PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件。 该插件目前支持