分页助手入门以及小bug,报sql语法错误

导入坐标

5版本以上的分页助手 可以不用手动指定数据库语言,它会自动识别

<dependency>

<groupId>com.github.pagehelper</groupId>

<artifactId>pagehelper</artifactId>

<version>5.3.2</version>

</dependency>

在mybaits核心配置文件里面配置插件

<plugins>

<plugin interceptor="com.github.pagehelper.PageInterceptor">

</plugin>

</plugins>

代码中使用

PageHelper.startPage(1,3); 第一个参数是当前页,第二个参数是每页显示的数据

PageInfo<T>()获得分页的所有参数

第一个泛型参数是对谁查询的实体类,第二个参数是要分页的数据列表

java 复制代码
        ArrayList<User> userList = mapper.getUserList();
        PageInfo<User> userPageInfo = new PageInfo<>(userList);

        System.out.println("当前页"+userPageInfo.getPageNum());
        System.out.println("每页显示条数"+userPageInfo.getPageSize());
        System.out.println("总条数"+userPageInfo.getTotal());
        System.out.println("总页数"+userPageInfo.getPages());
        System.out.println("上一页"+userPageInfo.getPrePage());
        System.out.println("下一页"+userPageInfo.getNextPage());
        System.out.println("是否是第一页"+userPageInfo.isIsFirstPage());
        System.out.println("是否是最后一页"+userPageInfo.isIsLastPage());

bug

映射文件

<select id="getUserList" resultType="org.pojo.User">

select * from mybatis.user;

</select>

当有分号时

会报语法错误

Preparing: select * from mybatis.user; LIMIT ?

==> Parameters: 3(Integer)

org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 3' at line 2

解决方法

去掉分号即可,因为分页助手会自动加分号

相关推荐
nongcunqq14 小时前
abap 操作 excel
java·数据库·excel
rain bye bye15 小时前
calibre LVS 跑不起来 就将setup 的LVS Option connect下的 connect all nets by name 打开。
服务器·数据库·lvs
阿里云大数据AI技术16 小时前
云栖实录|MaxCompute全新升级:AI时代的原生数据仓库
大数据·数据库·云原生
不剪发的Tony老师17 小时前
Valentina Studio:一款跨平台的数据库管理工具
数据库·sql
重生之我要当java大帝17 小时前
java微服务-尚医通-编写医院设置接口下
java·开发语言·sql
weixin_3077791317 小时前
在 Microsoft Azure 上部署 ClickHouse 数据仓库:托管服务与自行部署的全面指南
开发语言·数据库·数据仓库·云计算·azure
六元七角八分17 小时前
pom.xml
xml·数据库
虚行17 小时前
Mysql 数据同步中间件 对比
数据库·mysql·中间件
奥尔特星云大使18 小时前
mysql读写分离中间件Atlas安装部署及使用
数据库·mysql·中间件·读写分离·atlas
牛马baby18 小时前
【mysql】in 用到索引了吗?
数据库·mysql·in