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>
将第一个# 改为 $,具体原因有待研究。
<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>
将第一个# 改为 $,具体原因有待研究。
相关文章推荐
- MySQL笔记-jdbc编程步骤
- SQL Server创建和使用临时表(转)
- 利用MySQL的表实现树的构建以及优化
- 威力加强版SQL随机数字和字母
- redis之一内存回收
- Oracle数据库之PL/SQL程序设计基础
- 数据库设计原则(积累)
- mysql 5.7如何安装 mysql 5.7安装配置教程
- redis数据类型(List)
- 完整java开发中JDBC连接数据库代码和步骤 JDBC连接数据库
- oracle取数字,替换字符,查询树形结构,(+)
- redis数据类型(String)
- SQL Server 2012 新增语法
- mysql的master中slave的账号密码忘记的查看的办法
- C 链接mysql---预处理语句
- SQLServer还原 指定的转换无效解决方法
- 8天学通MongoDB——第八天 驱动实践
- 8天学通MongoDB——第七天 运维技术
- 8天学通MongoDB——第六天 分片技术
- 8天学通MongoDB——第五天 主从复制