1    首先需要在mybatis的配置文件SqlMapConfig.xml文件中配置pagehelper插件

<plugins>
       <plugin interceptor="com.github.pagehelper.PageHelper">
        <!--配置数据库的方言--> <property name="dialect" value="mysql"/> </plugin> </plugins>

  2   在spring配置文件中添加

<!--配置mybatis  -->
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property>
        <property name="dataSource" ref="dataSource"></property>
    </bean>

3         使用步骤

/**
*page为页码,rows为每页要显示多少条数据
*/

@Override
public DatagridBean selectAllUser(Integer page, Integer rows) throws Exception { PageHelper.startPage(page, rows); /*UserExample example = new UserExample(); List<User> users = userMapper.selectByExample(example);*/ List<User> users = customUserMapper.selectAllUsers(); PageInfo<User> pageInfo = new PageInfo<>(users); DatagridBean result = new DatagridBean(); result.setTotal(pageInfo.getTotal()); result.setRows(pageInfo.getList()); return result; }

 

相关文章:

  • 2021-12-07
  • 2021-09-29
  • 2021-10-20
  • 2021-07-21
  • 2022-01-31
猜你喜欢
  • 2021-10-31
  • 2021-05-23
  • 2021-11-03
  • 2022-12-23
  • 2021-12-10
相关资源
相似解决方案