1.if+where

<select id="getgoods" resultType="Goods" >

  select * from goods

  <where>

    <if test="name!=null and name!=' ' ">

        and name concat('%',#{name},'%')

    </if>

    <if test="条件">

        and .....

    </if>

  </where>

</select>

2.if+trim

(查询的)

    <trim prefix="where" prefixOverrides="and | or">

      <if test="条件">

        and .....

      </if>

    </trim>

(修改的)

    <trim prefix="set" sufixOverrides="," suffix="where id=#{id}">

      <if test="条件">

          name=#{name}

      </if>

    </trim>

3.if+set(用于修改)

update goods(表名)

<set>

  <if test="条件">

    name=#{name},

  </if>

</set>

where id=#{id}

4.foreach

<select id="getgoods" resultType="goods">

  select * from goods where price in

  <foreach collection="array" items="prices" open="("separator=","close=")">

    #{prices}

  </foreach>

</select>

collection:数组类型

    若参数类型是一个List(动态数组) collection属性值为list

    若参数类型是一个数组的时候 collection属性值为array

    备注:如果参多个参数的话就封装为一个Map

用法如下:

sql映射文件

test代码:

动态sql大致这么多,谢谢参考。

最新文章

  1. osx下配置Cocos2d-x 3.x Android开发环境
  2. 【jQuery UI 1.8 The User Interface Library for jQuery】.学习笔记.8.Datepicker控件
  3. iOS --- 通过openURL实现APP之间跳转并传递数据
  4. iOS字体设置
  5. js 如何获取文本框中光标索引位置
  6. XML DOM操作,适用目前流行的浏览器
  7. 【KMP】Oulipo
  8. ionic2 +Angular 使用自定义图标
  9. 深入解析Linux中的fork函数
  10. cocos2d-x 开发常见问题:
  11. ELK(elasticsearch+kibana+logstash)搜索引擎(一): 环境搭建
  12. Linux 小知识翻译 - 「Shell 脚本」
  13. Gravitee.io docker-compose运行
  14. windows7(64位) PHP APACHE MYSQL
  15. 【Cf #502 H】The Films(莫队)
  16. SQL的子查询操作
  17. 用 go 写 WebAssembly入门
  18. Java基础教程(7)--运算符
  19. PhoneGap获取设备信息
  20. Flask框架 之 第三方组件

热门文章

  1. 移动APP测试方法总结
  2. STM8学习
  3. vim环境设置(应用于python编程)
  4. Feature Scaling深入理解
  5. 用html+css+js做打地鼠小游戏
  6. 【学习】js学习笔记:数组(二)
  7. Django创建通用视图函数
  8. VB6文件操作自定义函数合集之一
  9. 深入浅出Diffie–Hellman
  10. js实现微信朋友圈模糊图片功能