先说解决方案:

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

再看 使用过程:

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. Crypt加密函数简介(C语言)

    定义函数 char * crypt (const char *key,const char * salt); 函数说明 crypt是个密码加密函数,它是基于Data Encryption Standa ...

  2. javascript初步了解

    0.1   <script> 和 </script> 会告诉 JavaScript 在何处开始和结束. <script> 和 </script> 之间的 ...

  3. HDU 2594 Simpsons’ Hidden Talents(KMP求s1前缀和s2后缀相同部分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目大意:给两串字符串s1,s2,,找到最长子串满足既是s1的前缀又是s2的后缀,输出子串,及相 ...

  4. Eolinker——前置用例返回的reponse值进行传递

    如下补充均是Eolinker的文档中未说明的部分 示例:将login接口reponse中的mobile的值作为参数,传递给”重置密码”的请求体“code" 1.打开”前置用例“,先点击左上角 ...

  5. float数据类型

    学习一门语言都要打好基础,前面的知识可能看着无聊,但是很重要,能够让我们打好坚实的基础,一定要掌握int.float.long.字符串.列表.元组.集合.字典.函数和类的基础常用的操作. 下面来看一看 ...

  6. c++ primer 11 泛型算法

    使用泛型算法必须包含头文件#inlucde <algorithm> 标准库还定义一组泛化的算术算法,其命名习惯与泛型算法相同,包含头文件#include <numeric> f ...

  7. 【LOJ】#2351. 「JOI 2017/2018 决赛」毒蛇越狱

    题解 没啥特别好的算法,是个讨论题,由于0 1 ?三类数位中最少的不会超过6 如果1不超过6,那么记录\(f1(S)\)为 \(\sum_{T \subset S} val(T)\)这个可以通过类似F ...

  8. loadrunner场景执行出现:Failed to Initialize. Reason: TimeOut

      问题1: Failed to Initialize. Reason: TimeOut LoadRunner的异常原因(Failed to Initialize. Reason: TimeOut) ...

  9. php中var_dump()函数

    var_dump() void var_dump ( mixed expression [, mixed expression [, ...]] ) var_dump()方法是判断一个变量的类型与长度 ...

  10. 《java虚拟机》----类加载机制

    No1: 实现语言无关性的基础仍然是虚拟机和字节码存储格式,虚拟机只与Class文件这种特定的二进制文件格式所关联,并不关心Class的来源是何种语言. No2: Class文件是一组以8位字节为基础 ...