MyBatis_Dynamic_SQL

SSM 框架学习 (MyBatis篇)

二、MyBatis 动态SQL使用

在上一个项目的基础上修改,这里主要展示修改部分的内容

1、用户表查询操作-if

select u.*, r.roleName from smbms_user u, smbms_role r

where u.userRole = r.id

and u.userRole = #{userRole}

and u.userName like CONCAT ('%',#{userName},'%')

2、 动态条件查询-if-where

select u.*, r.roleName from smbms_user u, smbms_role r

u.userRole = r.id

and u.userName like CONCAT ('%',#{userName},'%')

and r.userRole = #{userRole}

3、 动态条件更新数据-if-set

update smbms_user

userCode=#{userCode},

userName=#{userName},

userPassword=#{userPassword},

gender=#{gender},

birthday=#{birthday},

phone=#{phone},

address=#{address},

userRole=#{userRole},

modifyBy=#{modifyBy},

modifyDate=#{modifyDate}

where id=#{id}

4、 动态条件查找数据-if-trim-prefix-prefixOverrides

select * from smbms_user

and userName like CONCAT ('%',#{userName},'%')

and userRole = #{userRole}

5、 动态条件修改数据-if-trim-prefix-suffixOverrides-suffix

update smbms_user

userCode=#{userCode},

userName=#{userName},

userPassword=#{userPassword},

gender=#{gender},

birthday=#{birthday},

phone=#{phone},

address=#{address},

userRole=#{userRole},

modifyBy=#{modifyBy},

modifyDate=#{modifyDate},

6、 动态条件查找数据-foreach-array

select * from smbms_user where userRole in

#{roleIds}

7、 动态条件查找数据-foreach-list

select * from smbms_user where userRole in

#{roleIdList}

8、 动态条件查找数据-foreach-map

select * from smbms_user where userRole in

#{roleIdMap}

9、 动态条件查找数据-trim-choose

select * from smbms_user

and userName like CONCAT ('%',#{userName},'%')

and userCode like CONCAT ('%',#{userCode},'%')

and userRole = #{userRole}

and YEAR(creationDate) = YEAR(#{creationDate})

10、动态条件查询用户列表-分页查询

select u.*, r.roleName from smbms_user u, smbms_role r

where u.userRole = r.id

and u.userRole = #{userRole}

and u.userName like CONCAT ('%',#{userName},'%')

order by u.creationDate DESC limit #{from}, #{pageSize}

@Author: 瞌睡虫

@mybatis-3.2.2

@Database: mysql 5.7.15

@Tool: MyEclipse

mysql lsl_GitHub - LSL-Git/MyBatis_Dynamic_SQL: mybatis 动态SQL使用相关推荐

  1. MyBatis动态SQL(认真看看, 以后写SQL就爽多了)

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 来源:cnblogs.com/homejim/p/9909657. ...

  2. 认真看看, 以后写 SQL 就爽多了:MyBatis 动态 SQL:

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 作者 | 阿进的写字台 来源 | cnblogs.com ...

  3. MyBatis动态SQL,写SQL更爽

    点击上方 好好学java ,选择 星标 公众号重磅资讯,干货,第一时间送达 今日推荐:分享一套基于SpringBoot和Vue的企业级中后台开源项目,这个项目有点哇塞!个人原创100W +访问量博客: ...

  4. 认真看看, 以后写 SQL 就爽多了:MyBatis 动态 SQL

    点击上方 好好学java ,选择 星标 公众号 重磅资讯.干货,第一时间送达今日推荐:2020年7月程序员工资统计,平均14357元,又跌了,扎心个人原创100W+访问量博客:点击前往,查看更多 整理 ...

  5. (4) hibernate增删查改+批量操作+类似Mybatis动态sql

    简介 采用spring + hibernate + freemaker+ maven搭建起来的一个hibernate增删查改和 类似mybatis动态sql查询的一个案例 增删查改demo + 动态s ...

  6. 后端技术:MyBatis动态SQL写法介绍

    MyBatis 令人喜欢的一大特性就是动态 SQL.在使用 JDBC 的过程中, 根据条件进行 SQL 的拼接是很麻烦且很容易出错的.MyBatis 动态 SQL 的出现, 解决了这个麻烦. MyBa ...

  7. MyBatis动态SQL使用

    MyBatis令人喜欢的一大特性就是动态SQL.在使用JDBC的过程中, 根据条件进行SQL的拼接是很麻烦且很容易出错的.MyBatis动态SQL的出现, 解决了这个麻烦.MyBatis通过OGNL来 ...

  8. 【MyBatis动态SQL批量修改数据出现报错问题】

    MyBatis动态SQL批量修改数据出现报错问题 MyBatis动态SQL批量修改数据出现报错问题 问题描述 XML文件中的动态SQL 执行结果 测试执行 报错日志 解决 原数据库URL 修改后数据库 ...

  9. Mybatis—动态SQL语句与逆向工程

    Mybatis动态SQL语句与逆向工程 MyBatis动态SQL语句与逆向工程 1.动态SQL语句 1.1.动态SQL是什么 1.2.动态SQL有什么用 1.3.基于XML的实现 1.3.2.接口文件 ...

  10. MyBatis 动态 SQL,讲的很细

    点击上方蓝色字体,选择"标星公众号" 优质文章,第一时间送达 整理:阿进的写字台 原文:cnblogs.com/homejim/p/9909657.html MyBatis 令人喜 ...

最新文章

  1. TensorRT 基于Yolov3的开发
  2. 几何匹配和分合算法的图像识别技术
  3. php esi技术,Php环境搭建 – 巴黎高等计算机学院(ESI-SUPINFO)中国校区技术博客...
  4. 如何解决U盘无法停止通用卷设备
  5. java9-1.类,抽象类,接口的综合小练习
  6. Xshell登录Linux服务器 提示WARNING! The remote SSH server rejected X11 forwarding request 及 提示符显示-bash-4.2#
  7. Abp vnext Web应用程序开发教程 1 —— 创建服务器端
  8. 十四、View Port 2.0
  9. win10计算机系统优化设置,有效提升Win10运行速度的基本优化设置方案
  10. 尚硅谷大数据开发Day03
  11. win10开机自动运行bat脚本
  12. Excel如何快速统计指定填充颜色的数据个数
  13. 单片机反相器_TTL反相器的基本电路
  14. 一本通1348:城市公交网建设问题
  15. PA认证考试说明及注意事项
  16. 行转换html,块级、行内、行内元素相互转换
  17. 2014 年终总结:即使艰难,也要始终怀揣梦想
  18. C#采集麦克风话筒声音
  19. 【vulhub靶场】medium_socnet
  20. latex安装教程(texlive+texstudio)并添加IEEE模板

热门文章

  1. 《从零开始的 RPG 游戏制作教程》第五期:制作物品和技能
  2. html5 邮箱后缀自动填写,Ant Design Vue AutoComplete 通过自定义选项search实现如自动补充邮箱后缀功能...
  3. 查看TRP开头的数据量超过1000000的表的index情况
  4. 【前端开发】在windows 10上安装gulp(详细讲解)
  5. 更新来袭!新增语音添加待办、邮箱通知等功能
  6. 差劲的PHP后端开发,【后端开发】Php为什么性能差
  7. Groundhog Looking Dowdy
  8. cython使用初步
  9. iterative(迭代的) 和recursive(递归的)的区别
  10. Visual Prompt Tuning (VPT)