mybatis order by后面参数是string类型的疑惑

zijiaobingbu 2014-03-18 12:00:47
<select id="selectHotGoods" parameterType="java.lang.String" resultType="Goods">
select * from goods where state = 1
order by ${sort}
limit 4
</select>

MyBatis排序时使用order by 动态参数时需要注意,用$而不是#,但是如果用$就会报There is no getter for property named 'XXX' in 'class java.lang.String' ,而改成#后,不会报错,参数能传进去,但是得到的结果order by 不起作用,就是没有按照我想要的类型排序。所以这里很纠结,求大神解答。
...全文
1711 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccc234567 2014-11-17
  • 打赏
  • 举报
回复
时间过了这么久啊,我来回复一下吧。 可以确定的是order by 后面是应该使用${sort},你的报错应该是没有绑定的对应的参数吧 在你的java mapper类的方法里应该加上@Param(value="sort")来绑定吧?
chaoil 2014-07-02
  • 打赏
  • 举报
回复
s参数名改为 _parameter
zijiaobingbu 2014-03-20
  • 打赏
  • 举报
回复
哎,都四天了,自己顶一下吧
zijiaobingbu 2014-03-18
  • 打赏
  • 举报
回复
难道是我说的不清楚吗?在补充一下: 使用 # 号是,不会出错,日志打出的sql语句如下, DEBUG - ==> Preparing: select * from goods where state = 1 order by ? desc limit 4 DEBUG - ==> Parameters: salesVolume(String) 但是结果是order by没有起作用。 使用 $ ,就会有如下错误: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'sort' in 'class java.lang.String'。

5,655

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧