baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.35k stars 4.3k forks source link

使用mapper的selectPage方法做分页报错 #433

Closed WindWZQ closed 6 years ago

WindWZQ commented 6 years ago

当前使用版本(必须填写清楚,否则不予处理)

<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatisplus-spring-boot-starter</artifactId>
  <version>1.0.5</version>
</dependency>
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus</artifactId>
  <version>2.1.9</version>
</dependency>

该问题是怎么引起的?

使用mapper的selectPage方法做分页

重现步骤

EntityWrapper<UserBean> entityWrapper = new EntityWrapper<>();
userMapper.selectPage(new RowBounds(5, 5), entityWrapper);

报错信息

### Error querying database.  Cause: com.microsoft.sqlserver.jdbc.SQLServerException: “5”附近有语法错误。
### The error may exist in com/check/user/mapper/UserMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT  id,phone,account,hashed,open_id AS openId,name,age,head_path AS headPath,role_id AS roleId  FROM service_users OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: “5”附近有语法错误。
uncategorized SQLException for SQL []; SQL state [S0001]; error code [102]; “5”附近有语法错误。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: “5”附近有语法错误。] with root cause

后来发现是没有order by造成的,建议默认使用主键排序。

miemieYaho commented 6 years ago

使用该版本的bootstart试试:mybatis-plus-boot-starter 你使用的是老版本的,新版不需要再自己引入mp的依赖