ssm工程集成mybatis分页插件pagehelper
2024-10-11 02:50:34
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;
}
最新文章
- CentOS6.4 安装Sphinx 配置MySQL数据源
- iOS学习资料
- iOS XML &#160;解析(原生的)
- Chrome内嵌 FlashPlayer(PPAPI)会被页面DHTML元素遮住的问题
- python 有关矩阵行列的存取 np.array
- MsoShapeType /InlineShape枚举
- Linux C判断日期格式是否合法
- VC++ 控制台不自动退出
- javascript中用来定义引用类型的一种";默认";模式
- JAVA----类的继承1(extends)
- css 弹性盒兼容性写法,直接复制粘贴
- Free Goodies UVA - 12260 贪心
- C# linq左连接与分组
- IDEA2017.3.3创建第一个javaweb项目及tomcat部署实战
- tf.variable和tf.get_Variable以及tf.name_scope和tf.variable_scope的区别
- Charles抓包软件简介
- MyBatis基础:MyBatis调用存储过程(6)
- Jquery中 .empty()和.append()
- 了解可执行的NPM包
- ffmpeg文件切片