mybatis 动态sql
来源:互联网 发布:开淘宝店自己没有货 编辑:程序博客网 时间:2024/06/11 04:25
四 , xmlmapper 文件中sql 语句解析
解析类 XMLLanguageDriver ,可以通过setting 中的配置解析类。
XMLScriptBuilder 动态sql 语句
"bind":BindHandler
<if test="sex !=null"> <bind name="sexConvert" value='sex == "男" ? "M": "F"' />and sex = #{sexConvert ,jdbcType=VARCHAR}</if>通过ognl 计算值,赋值给变量
ForEachHandler : forecah 标签的解析解析
<select id="selectInByList" resultType="blog" >select * from blog where id in<foreach item="item" index="index" collection="array"open="(" separator="," close=")">#{item}</foreach></select><select id="selectInByMap" resultType="blog" parameterType="map">select * from blog where id in<foreach item="item" index="index" collection="ids"open="(" separator="," close=")">#{item}</foreach></select>
foreach 标签 属性 collection的取值
1.当参数为数组的时候 为 array,
2.为集合的时候 是 collection ,如何是 list类型的时候是list,
3. 当参数为map时,是集合对应的key,为对象时,是对象对应的属性
IfSqlNode if 标签
1.使用ognl 表达式对test 条件进行属性判断
ognl 使用属性名称表示属性 , string " " ,char ' ' ,数字 , null 表示为空 , true and false.
<if test="_parameter.getOrderBy()">order by title</if>
test 中进行判断 != , == 调用方法 _parameter.getOrderBy()
trim : TrimHandler TrimSqlNode
<select id="selectTrim" resultType="blog" parameterType="blog"> select * from blog <trim prefix="where" prefixOverrides="and | or"> <if test="title != null"> and title like #{title}"%" </if> <if test="author != null"> and author=#{author} </if> </trim> </select>
prefixesToOverride 以 | 分割 删除头部出项的字符
suffixesToOverride 以 | 分割 删除尾部出项的字符
prefix 如果内容不为空,在头部添加的字符
suffix 如果内容不为空,在尾部添加的字符
"where",WhereHandler 继承自 trimhandler
prefixesToOverride AND, OR
prefix WHERE
set : SetHandler 继承自 trimhandler
suffix SET
suffixesToOverride , 逗号
;
when : IfHandler
choose ChooseHandler ChooseSqlNode
相当于switch
when 相对于 case 比配成功就跳出 ,OtherwiseHandler 相对于 default
<select id="selectChoose" resultType="blog" parameterType="blog"> select * from blog where 1=1 <choose> <when test="title != null"> and title like #{title}"%" </when> <when test="author != null"> and author=#{author} </when> <otherwise> and id < 5 </otherwise> </choose> </select>
- mybatis动态SQL语句
- MyBatis动态SQL
- MyBatis 动态SQL
- Mybatis 动态SQL
- MyBatis动态SQL
- MyBatis动态SQL完整版
- mybatis动态sql
- mybatis动态SQL语句
- mybatis动态SQL语句
- MyBatis的动态SQL
- MyBatis动态SQL
- MyBatis动态SQL
- MyBatis 动态SQL语句
- MyBatis动态SQL
- Mybatis组建动态SQL
- MyBatis 动态sql
- mybatis 动态SQL语句
- MyBatis动态SQL详解
- 【Effection C++】读书笔记 条款26:尽可能延后变量定义式的出现时间
- 关于threadlocal
- 弹窗遮罩的几种实现方式
- React Native 从入门到原理
- Web11页面布局
- mybatis 动态sql
- 庖丁解牛之内存
- C# 中的Retry 模型
- 06-图2 Saving James Bond
- c++模版链表的实现
- 关于马尔科夫随机场MRF的思考
- golang中解决tcp传输中的粘包问题
- API接口安全性设计
- 【图像特征提取1】方向梯度直方图HOG---从理论到实践------附带积分图像的解析