先说解决方案:

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

再看 使用过程:

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. linux的fwrite()使用方法,当前时间写入文本的程序

    fwrite函数 1.函数功能 用来读写一个数据块. 2.一般调用形式 fwrite(buffer,size,count,fp); 3.说明 (1)buffer:是一个指针,对fread来说,它是读入 ...

  2. 关于函数strtok和strtok_r的使用要点和实现原理

    strtok函数的使用是一个老生常谈的问题了.该函数的作用很大,争议也很大.以下的表述可能与一些资料有区别或者说与你原来的认识有差异,因此,我尽量以实验为证.交代一下实验环境是必要的,winxp+vc ...

  3. 关于真多核和加多核&线程由哪几部分组成

    网上查的资料小结,没有考证. 真多核是指一个cpu多个核心,即多个内核. 假多核是指多个cpu捆绑形成的分布式计算,ARM针对服务器市场推出的处理器为多个cpu的 真多核的应用奔腾和因特尔 双核芯cp ...

  4. hive学习(八)hive优化

    Hive 优化 1.核心思想: 把Hive SQL 当做Mapreduce程序去优化 以下SQL不会转为Mapreduce来执行 select仅查询本表字段 where仅对本表字段做条件过滤   Ex ...

  5. 洛谷 P1897电梯里的爱情 题解

    题目传送门 对于每个输入的第i个人,直接使用桶,但注意范围要开大一些. #include<bits/stdc++.h> using namespace std; ],x,sum,h,Max ...

  6. jquery自定义插件-参数化配置多级菜单导航栏插件

    1 自定义菜单导航栏插件的必要性 看图说话,下面是利用自定义的菜单导航栏插件simpleMenu创建的网站导航示例: 插件默认提供的是如上图的导航栏样式,即一二级菜单为横向分布:三四级菜单为纵向分布. ...

  7. vscode vue配置和一些其它辅助【工具篇】

    后续有补充就经常更新

  8. sql获取的时间不能直接在c#中tostring成我们要的格式,要转化一下

    DateTime.Parse(Model.Rows[0]["datevalidbegin"].ToString()).ToString("yyyy-MM-dd" ...

  9. HTML中的Div Span label的区别

    div与span 大家在初学div+css布局时,有很多困惑,在div与span的使用过程没觉得有一定的”章法”,觉得两个区别不大,在w3c的关于div和span的定义:div作为分割文档结构自然使它 ...

  10. (转)Ubuntu 16.04 安裝Docker(PS:本文适用amd64位的ubuntu系统)

    1.前置安裝,確保你的系統是64位 $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-p ...