1.第一种情况SQL报错
> 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 5'
> at line 3
原因:在xml写的sql带了分号,由于PageHelper会在sql尾部追加limit,所以导致生成sql时有误,导致错误。
错误写法:
<select id="selectAll" resultMap="BaseResultMap">
SELECT * FROM student;
</select>
正确写法:
<select id="selectAll" resultMap="BaseResultMap">
SELECT * FROM student
</select>
2.第二种情况分页无效
原因:可能是代码前后顺序有问题,应该先写分页,再执行sql。
错误写法:
List<Student> students = studentMapper.selectAll();
PageHelper.startPage(1, 5, true);
正确写法:
PageHelper.startPage(1, 5, true);
List<Student> students = studentMapper.selectAll();