Mybatis映射文件中的标签的使用
<foreach>
<!-- foreach -->
<delete id="delMulti" parameterType="java.util.List">
delete from user where id in
<!--collection:输入参数为List集合时,必须写list,
item:为集合里的每一项起名,可以任意定义
separator:每一项中间的分割符
open:在执行循环体之前拼接的内容;
close:在执行循环体之后拼接的内容;-->
<foreach collection="list" item="uid" separator="," open="(" close=")">
#{uid}
</foreach>
</delete>
where
<!--where:解析成where关键字,会自动去掉第一个符合条件的限定条件中的and -->
<select id="getByNameSex" parameterType="map" resultType="user">
select * from user
<where>
<if test="uname!=null and uname!=''">
and username like "%"#{uname}"%"
</if>
<if test="usex!=null and usex!=''">
and sex=#{usex}
</if>
</where>
choose when otherwise
<!--choose when otherwise:某个判断满足条件后,其他条件就不会再执行 -->
<select id="getByNameSex1" parameterType="map" resultType="user">
select * from user where
<choose>
<when test="uname!=null and uname!=''">
username like "%"#{uname}"%"
</when>
<when test="usex!=null and usex!=''">
sex=#{usex}
</when>
<otherwise>
1=1
</otherwise>
</choose>
</select>
set
<!-- set:解析为set关键字,可以自动去掉最后一个更新的字段后面的逗号 -->
<update id="updUser" parameterType="user">
update user
<set>
<if test="username!=null and username!=''">
username=#{username},
</if>
<if test="sex!=null and sex!=''">
sex=#{sex}
</if>
</set>
where id=#{id}
</update>
trim:使用次数较少
<update id="updUser1" parameterType="user">
<!--prefix:前缀,在trim中内容执行之前拼接
suffix:后缀:在trim中内容执行之后拼接
suffixOverrides:忽略后缀
prefixOverrides:忽略前缀-->
<trim prefix="update user set" suffix="where id=#{id}" suffixOverrides=","> <if test="username!=null and username!=''">
username=#{username},
</if>
<if test="sex!=null and sex!=''">
sex=#{sex}
</if> </trim>
</update>
bind使用较少
<select id="getByUname" parameterType="string" resultType="User">
<!--name:新的字符串的变量名 -->
<bind name="uname" value="'%'+_parameter+'%'"/>
select * from user where username like #{uname}
</select>
Mybatis映射文件中的标签的使用的更多相关文章
- Mybatis映射文件中#取值时指定参数相关规则
Mybatis映射文件中#取值时指定参数相关规则 在#{}中,除了需要的数值外,还可以规定参数的一些其他规则. 例如:javaType,jdbcType,mode(存储过程),numericScale ...
- Mybatis映射文件中的参数传递
一.接口中只有一个参数 1.参数是基本类型or基本类型的包装类or字符串类型 这种情况下映射文件中#{}里的内容可以是任意的,你可以使用#{xxx} 或 #{abc} .....因为此时#{}相当于一 ...
- Mybatis映射文件中数据库表列名称和POJO成员域的联系
下面是Mybatis的SQL映射文件. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ma ...
- 018 关联映射文件中<class>标签中的lazy(懒加载)属性
Lazy(懒加载): 只有在正真使用该对象时,才会创建这个对象 Hibernate中的lazy(懒加载): 只有我们在正真使用时,它才会发出SQL语句,给我们去查询,如果不使用对象则不会发SQL语句进 ...
- 019 关联映射文件中集合标签中的lazy(懒加载)属性
<set>.<list>集合上,可以取值:true/false/extra,(默认值为:true) 实例一:(集合上的lazy=true(默认))class默认lazy=tru ...
- [刘阳Java]_MyBatis_映射文件的常用标签总结_第5讲
MyBatis中常用标签的总结,简单给出自己的总结 MyBatis映射文件中的标签使用介绍1.<select>:用于编写查询语句用的标签 id:表示当前<select>标签的唯 ...
- [刘阳Java]_MyBatis_映射文件的select标签入门_第3讲
1.Mybatis映射文件的<select>标签主要帮助我们完成SQL语句查询功能,<select>标签它包含了很多属性,下面简单对<select>标签的属性做一个 ...
- MyBatis 映射文件详解
1. MyBatis 映射文件之<select>标签 <select>用来定义查询操作; "id": 唯一标识符,需要和接口中的方法名一致; paramet ...
- Mybatis映射文件标签(关于sql)
Mybatis映射文件 1.接口的全限定名和映射文件的namespace一致 <mapper namespace="com.offcn.dao.UserDao"> 2. ...
随机推荐
- 2017 ICPC网络赛(西安)--- Xor
题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai≤1,000 ...
- E08【选尺码】I'm looking for size 43
核心句型 I'm looking for size 43 我想要43号的 场景对话 A:Can I help you?您需要什么? B:Yes,can I try on those shoes,ple ...
- IDEA 一键生成所有setter方法(GenerateAllSetter插件)
GenerateAllSetter插件使用效果如下: alt+enter快捷键选择Generate all setter 之后就会自动生成其中的所有setter方法 下面介绍idea安装步骤: alt ...
- GCC 预处理,汇编,编译,链接,连接静态库,动态库
gcc Record gcc -E file1.c > output gcc -E file1.c -o file1.i gcc -S file1.i -o file1.s gcc -S fil ...
- 莫烦TensorFlow_03 Variable加法
import tensorflow as tf ## 定义变量 state = tf.Variable(0, name = 'counter') #print(state.name) one = tf ...
- Kubernetes 记一次网络请求分析
查看pod,server root @ master ➜ ~ kubectl get po,svc -n irm-server -o wide NAME READY STATUS RESTARTS A ...
- CF13B Letter A
CF13B Letter A 洛谷传送门 题目描述 Little Petya learns how to write. The teacher gave pupils the task to writ ...
- 关于git设置多个账号的问题,ideal中clone项目
一.排坑 1.ping github.com超时.修改C:\Windows\System32\drivers\etc的hosts文件,添加 # GitHub地址 192.30.255.112 gith ...
- 【转】TCP连接突然断开的处理方法
TCP是因特网中的传输层协议,使用三次握手协议建立连接,下面是TCP建立连接的全过程. TCP断开连接的过程:TCP四次挥手. TCP/IP 协议簇分层结构 数据链路层主要负责处理传输媒介等众多的物理 ...
- mission3--dp
A---母牛的故事 题目大意:第一年有一头母牛,每年年初母牛生小母牛,小母牛第四个年头可以开始生小牛. 问第n年有多少头牛. 题解: (1)列出前几项来找规律(2)第i年牛的数量=第i-1年牛的数量+ ...