先说解决方案:

注意  只需要把#{} 改成 ${}  即可

再看 使用过程:

Mapper.java

List<IntegralGoods> findInUid(@Param("uidList") List<String> uidList,@Param("order") String order,@Param("orderType") String orderType);

首先,是这样的mybatis拼接的sql语句

<select id="findInUid" parameterType="com.pisen.cloud.luna.ms.jifen.base.domain.IntegralGoods" resultMap="baseResBean">

        select
a.id as 'id',
a.uid as 'uid',
a.create_date as 'createDate',
a.update_date as 'updateDate',
a.update_id as 'updateId',
a.create_id as 'createId',
a.brand_uid as 'brandUid',
a.tid as 'tid',
a.stock as 'stock',
a.name as 'name',
a.goods_code as 'goodsCode',
a.market_value as 'marketValue',
a.specification as 'specification',
a.remark as 'remark',
a.type as 'type',
a.integral as 'integral',
a.description as 'description',
a.sale_num as 'saleNum',
a.limit_num as 'limitNum',
a.shelf_flag as 'shelfFlag',
a.home_show_flag as 'homeShowFlag',
sl.shelf_date as 'shelfDate',
sl.obtained_date as 'obtainedDate',
b.id b_id,
b.src b_src,
b.type b_type,
b.sort b_sort
from
integral_goods a
left join
integral_goods_img b
on
a.uid = b.integral_goods_id
left join
shelf_log sl
on
a.uid = sl.integral_goods_uid
<where>
a.uid
IN
<foreach collection="uidList" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
<if test="order != null and orderType">
order by #{order} #{orderType}
</if>
</where> </select>

执行的sql语句是这样:

SELECT
a.id AS 'id',
a.uid AS 'uid',
a.create_date AS 'createDate',
a.update_date AS 'updateDate',
a.update_id AS 'updateId',
a.create_id AS 'createId',
a.brand_uid AS 'brandUid',
a.tid AS 'tid',
a.stock AS 'stock',
a. NAME AS 'name',
a.goods_code AS 'goodsCode',
a.market_value AS 'marketValue',
a.specification AS 'specification',
a.remark AS 'remark',
a.type AS 'type',
a.integral AS 'integral',
a.description AS 'description',
a.sale_num AS 'saleNum',
a.limit_num AS 'limitNum',
a.shelf_flag AS 'shelfFlag',
a.home_show_flag AS 'homeShowFlag',
sl.shelf_date AS 'shelfDate',
sl.obtained_date AS 'obtainedDate',
b.id b_id,
b.src b_src,
b.type b_type,
b.sort b_sort
FROM
integral_goods a
LEFT JOIN integral_goods_img b ON a.uid = b.integral_goods_id
LEFT JOIN shelf_log sl ON a.uid = sl.integral_goods_uid
WHERE
a.uid IN (
'09f163c30c504d7fb571186db9c10ff3',
'd8a9184443524e369be59417e9edd409',
'778b5c0fbc4141b4bd8de3b7756a1d9d',
'58d53fe0126d47c8bf382647244e2b1d'
)
ORDER BY
'integral' 'asc'

这样执行sql  是没有效果的 !!!

正确的

<select id="findInUid" parameterType="com.pisen.cloud.luna.ms.jifen.base.domain.IntegralGoods" resultMap="baseResBean">

        select
a.id as 'id',
a.uid as 'uid',
a.create_date as 'createDate',
a.update_date as 'updateDate',
a.update_id as 'updateId',
a.create_id as 'createId',
a.brand_uid as 'brandUid',
a.tid as 'tid',
a.stock as 'stock',
a.name as 'name',
a.goods_code as 'goodsCode',
a.market_value as 'marketValue',
a.specification as 'specification',
a.remark as 'remark',
a.type as 'type',
a.integral as 'integral',
a.description as 'description',
a.sale_num as 'saleNum',
a.limit_num as 'limitNum',
a.shelf_flag as 'shelfFlag',
a.home_show_flag as 'homeShowFlag',
sl.shelf_date as 'shelfDate',
sl.obtained_date as 'obtainedDate',
b.id b_id,
b.src b_src,
b.type b_type,
b.sort b_sort
from
integral_goods a
left join
integral_goods_img b
on
a.uid = b.integral_goods_id
left join
shelf_log sl
on
a.uid = sl.integral_goods_uid
<where>
a.uid
IN
<foreach collection="uidList" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
<if test="order != null and orderType">
order by ${order} ${orderType}
</if>
</where> </select>

执行的sql语句是这样的:

SELECT
a.id AS 'id',
a.uid AS 'uid',
a.create_date AS 'createDate',
a.update_date AS 'updateDate',
a.update_id AS 'updateId',
a.create_id AS 'createId',
a.brand_uid AS 'brandUid',
a.tid AS 'tid',
a.stock AS 'stock',
a. NAME AS 'name',
a.goods_code AS 'goodsCode',
a.market_value AS 'marketValue',
a.specification AS 'specification',
a.remark AS 'remark',
a.type AS 'type',
a.integral AS 'integral',
a.description AS 'description',
a.sale_num AS 'saleNum',
a.limit_num AS 'limitNum',
a.shelf_flag AS 'shelfFlag',
a.home_show_flag AS 'homeShowFlag',
sl.shelf_date AS 'shelfDate',
sl.obtained_date AS 'obtainedDate',
b.id b_id,
b.src b_src,
b.type b_type,
b.sort b_sort
FROM
integral_goods a
LEFT JOIN integral_goods_img b ON a.uid = b.integral_goods_id
LEFT JOIN shelf_log sl ON a.uid = sl.integral_goods_uid
WHERE
a.uid IN (
'09f163c30c504d7fb571186db9c10ff3',
'd8a9184443524e369be59417e9edd409',
'778b5c0fbc4141b4bd8de3b7756a1d9d',
'58d53fe0126d47c8bf382647244e2b1d'
)
ORDER BY
integral ASC

【mybatis】mybatis动态order by 的问题, 注意 只需要把#{} 改成 ${} 即可的更多相关文章

  1. 利用MyBatis的动态SQL特性抽象统一SQL查询接口

    1. SQL查询的统一抽象 MyBatis制动动态SQL的构造,利用动态SQL和自定义的参数Bean抽象,可以将绝大部分SQL查询抽象为一个统一接口,查询参数使用一个自定义bean继承Map,使用映射 ...

  2. Java-MyBatis:MyBatis 3 动态 SQL

    ylbtech-Java-MyBatis:MyBatis 3 动态 SQL 1.返回顶部 1. 动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架 ...

  3. Mybatis中动态SQL语句中的parameterType不同数据类型的用法

    Mybatis中动态SQL语句中的parameterType不同数据类型的用法1. 简单数据类型,    此时#{id,jdbcType=INTEGER}中id可以取任意名字如#{a,jdbcType ...

  4. MyBatis 示例-动态 SQL

    MyBatis 的动态 SQL 包括以下几种元素: 详细的使用参考官网文档:http://www.mybatis.org/mybatis-3/zh/dynamic-sql.html 本章内容简单描述这 ...

  5. MyBatis的动态SQL详解

    MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑,本文详解mybatis的动态sql,需要的朋友可以参考下 MyBatis 的一个强大的特性之一通常是它 ...

  6. Mybatis解析动态sql原理分析

    前言 废话不多说,直接进入文章. 我们在使用mybatis的时候,会在xml中编写sql语句. 比如这段动态sql代码: <update id="update" parame ...

  7. mybatis 使用动态SQL

    RoleMapper.java public interface RoleMapper { public void add(Role role); public void update(Role ro ...

  8. (转)mybatis:动态SQL

    概述:在mybatis中,动态语句是个非常强大和灵活的功能,并且动态语句可以放在sql的任何地方,利用该功能,我们可以写出非常灵活的代码.在mybatis的动态语句中常常可能会用到以下几个运算和逻辑判 ...

  9. MyBatis框架——动态SQL、缓存机制、逆向工程

    MyBatis框架--动态SQL.缓存机制.逆向工程 一.Dynamic SQL 为什么需要动态SQL?有时候需要根据实际传入的参数来动态的拼接SQL语句.最常用的就是:where和if标签 1.参考 ...

随机推荐

  1. hdu 1907(Nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  2. PHP 执行系统外部命令的函数- system() exec() passthru()

    PHP 执行系统外部命令的函数: system() exec() passthru()区别:system() 输出并返回最后一行shell结果.exec() 不输出结果,返回最后一行shell结果,所 ...

  3. git团队开发

    用git有一年了,下面是我这一年来的git使用总结,覆盖了日常使用中绝大多数的场景.嗯,至少是够用一年了,整理出来分享给大家,不明白的地方可以回复交流. git设置关闭自动换行 git config ...

  4. SGU 217. Two Cylinders

    题意:给空间内两根圆柱,求轴线垂直相交时公共部分的体积. 暴力积分即可. ID: Date'n'Time: Name: Task: .Ext: Status: Time: Memory: 158937 ...

  5. android开发笔记,杂

    Mapping文件地址: mapping文件用于在代码被混淆后,还原BUG信息. release模式编译项目即可产生,相对位置:工程\build\outputs\mapping\release 需要c ...

  6. Canvas进阶——制作小游戏【贪吃蛇】

    今天呢,主要和小伙伴们分享一下一个贪吃蛇游戏从构思到实现的过程~因为我不是很喜欢直接PO代码,所以只copy代码的童鞋们请出门左转不谢. 按理说canvas与其应用是老生常谈了,可我在准备阶段却搜索不 ...

  7. loadrunner脚本编写http协议

  8. web_reg_save_param_regexp函数的用法

    关联从服务器返回的所有的内容: 本例通过一个使用HTTP/HTML协议发送.获取服务器数据的vuser脚本,分析LoadRunner如何进行HTTP关联. 下面这个例子包括两个事务:上传数据到服务器. ...

  9. Good Bye 2014 E - New Year Domino 单调栈+倍增

    E - New Year Domino 思路:我用倍增写哒,离线可以不用倍增. #include<bits/stdc++.h> #define LL long long #define f ...

  10. (转)Where与Having的总结

    Where 是一个约束声明,使用Where来约束来之数据库的数据,Where是在结果返回之前起作用的,且Where中不能使用聚合函数. Having 是一个过滤声明,是在查询返回结果集以后对查询结果进 ...