您的位置:首页 > 数据库

mybatis sqlserver 分页查询报错:'@P0' 附近有语法错误

2016-08-11 10:52 531 查看
错误的sql

<select id="searchEcoInfoPaged" resultMap="cm">
select TOP #{rows} * from eco_info where ID in
(
SELECT top (#{rows}*#{page}) ID FROM eco_info WHERE 1=1
<foreach collection="fieldMap" index="key" item="item" open="" separator=" " close="">
<if test="item != null and item != ''">
AND ${key} LIKE '%'+#{item}+'%'
</if>
</foreach>
order by ID DESC
)
order by ID ASC
</select>

正确的sql
<select id="searchEcoInfoPaged" resultMap="cm">
select TOP ${rows} * from eco_info where ID in
(
SELECT top (#{rows}*#{page}) ID FROM eco_info WHERE 1=1
<foreach collection="fieldMap" index="key" item="item" open="" separator=" " close="">
<if test="item != null and item != ''">
AND ${key} LIKE '%'+#{item}+'%'
</if>
</foreach>
order by ID DESC
)
order by ID ASC
</select>

将第一个# 改为 $,具体原因有待研究。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: