先说解决方案:

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

再看 使用过程:

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. udev和rules使用规则

    本文以通俗的方法阐述 udev 及相关术语的概念.udev 的配置文件和规则文件,然后以 Red Hat Enterprise Server 为平台演示一些管理设备文件和查询设备信息的实例.本文会使那 ...

  2. 使用php扩展mcrypt实现AES加密

    AES(Advanced Encryption Standard,高级加密标准)是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用.Rijndael是 ...

  3. naive cube implementation in python

    这篇论文中提到的naive cube算法的实现,python写出来真的就和伪代码差不多=.= 输入大约长这样,依次是 index userid country state city topic cat ...

  4. bzoj 1131 简单树形dp

    思路:随便想想就能想出来啦把...  卡了我一个vector... #include<bits/stdc++.h> #define LL long long #define fi firs ...

  5. ul>li中自定义属性后取值的问题

    动态赋值的li: $.ajax({ type: "POST", url: "${base}/before/subDemand/listType", succes ...

  6. DDL DML DCL DQL的区别

    原文章出处:http://blog.csdn.net/tomatofly/article/details/5949070 SQL(Structure Query Language)语言是数据库的核心语 ...

  7. BNUOJ 52503 Disdain Chain

    暴力,结论. 本打算写一发暴力,然后直接交答案,之后发现无论$n$等于多少,每种图都存在长度为$n$的路径,中间还一直以为自己暴力写错了. #include<bits/stdc++.h> ...

  8. 将 Unity5.3 的老项目升级到 Unity 2018.3 遇到的些许问题。

    删除 ParticleEmmiter 等废弃的接口: 删除 WindowsSecurityContext System.Security.Principal.WindowsIdentity 在 .Ne ...

  9. 【Python】单例模式Singleton

    前两天一个面试被问到python中单例模式有几种实现方式,只答出了可以用元类实现...然后就想不起来了. 之后翻书,原来这些之前都见过的啊.... 1.手动实现真正创建实例的方法__new__()来实 ...

  10. AtcoderGrandContest 005 F. Many Easy Problems

    $ >AtcoderGrandContest \space 005 F.  Many Easy Problems<$ 题目大意 : 有一棵大小为 \(n\) 的树,对于每一个 \(k \i ...