错误信息如下:
org.springframework.jdbc.UncategorizedSQLException:
### Error querying database. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: “@P0”附近有语法错误。
### The error may exist in file [F:\demo\wxwl\wlcx\target\classes\mapping\CMMatcherMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT COID, CR_Idx, CR_Mode, CT_Mode, CR_Fate, RG_Code, RG_Name, AR_Code, AR_Name, CM_Code, CM_Name, CR_Addr, CR_Style, CR_Grade FROM CM_Matcher OFFSET ? ROWS FETCH NEXT ? ROWS ONLY
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: “@P0”附近有语法错误。
; uncategorized SQLException; SQL state [S0001]; error code [102]; “@P0”附近有语法错误。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: “@P0”附近有语法错误。
错误信息显示sql 有问题,但一看语法跟配置没有任何的问题
配置:
#分页插件
#pagehelper.dialect=sqlserver2012
pagehelper.reasonable=true
#支持通过 Mapper 接口参数来传递分页参数
pagehelper.support-methods-arguments=true
pagehelper.helper-dialect=sqlserver2012
pagehelper.params=count=countsql
pagehelper.pageSizeZero=true
mapper.xml:
<select id="getAll" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM CM_Matcher
</select>
将报错的sql 赋值到sqlser2012中执行才发现sql 有问题:
于是研究了一下2012版本的分页语法并不是标准的sql, 必须要添加order by 才能正常work, 参考: https://blog.wuliping.cn/post/sql-2012-new-features-of-offset-fetch-next-only
最后根据id 排序执行结果如下:
mapper 修改:
<select id="getAll" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM CM_Matcher ORDER BY COID
</select>