mybatis简单的分页查询语句,之前一直这么写,今天突然失败了
<select id="queryTest" parameterType="map" resultType="map">
select ...
limit #{offset} , #{limit}
</select>
以map中存放查询参数{"limit":10,"offset":0},异常信息:
org.springframework.jdbc.BadSqlGrammarException:
....
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ''0' , '10'' at line 9
猜测是公司dba升级了数据库,然后我手动指定了jdbcType=INTEGER发现还是一样的异常。
<select id="queryTest" parameterType="map" resultType="map">
select ...
limit #{offset,jdbcType=INTEGER} , #{limit,jdbcType=INTEGER}
</select>
各位,是不是我哪些错了?
这下就不会了,这样是不是就无法再用map传递参数了?
楼主确定这样之前可用? 楼主limit的是‘0’,'10'的形式,语法错误,应该是 limit 0,10 的形式,应该用 ${offset} , ${limit}好像。
map中是{"limit":10,"offset":0},没有传递字符串
问题是找到了,现在就该找入口了
肯定是传入了字符串。把sql日志打印出来,参数类型也打印出来