专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 数据库

Mybatis预编译order by 话语无法生效

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
Mybatis预编译order by 语句无法生效
在mybatis的xml语句中 根据情况不同 采用不同的排序方式
        <if test="ordercolumn != null">
            ORDER BY #{ordercolumn} DESC
        </if>

但是没有生效,参考别人意见后,原来预编译时,将ordercolumn字段名转为字符串String格式,比如ordercolumn="name", sql语句是
ORDER BY “name” DESC

所以排序无法生效。

    解决办法:将xml按如下修改
        <choose>
            <when test="ordertype!=null and ordertype==1">
                ORDER BY carindex DESC
            </when>
            <when test="ordertype!=null and ordertype==2">
                ORDER BY statdate DESC
            </when>
            <otherwise>
                ORDER BY carindex DESC
            </otherwise>
        </choose>


传参数ordertype使用枚举形式,排序生效。
问题解决
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: