本文主要是介绍分页助手入门以及小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); 第一个参数是当前页,第二个参数是每页显示的数据
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
解决方法
去掉分号即可,因为分页助手会自动加分号
这篇关于分页助手入门以及小bug,报sql语法错误的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!