微服务 教程
1085个小节阅读:196.3k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
<where>
可以代替sql中的where 1=1 和第一个and,更符合程序员的开发习惯,使用<where>
后的映射文件如下:
xxxxxxxxxx
<select id="findByCondition" resultType="com.itbaizhan.user.User" parameterType="com.itbaizhan.user.User">
select * from user
<where>
<if test="username != null and username.length() != 0">
username like #{username}
</if>
<if test="sex != null and sex.length() != 0">
and sex = #{sex}
</if>
</where>
</select>
<set>
标签用在update语句中。借助<if>
,可以只对有具体值的字段进行更新。<set>
会自动添加set关键字,并去掉最后一个if语句中多余的逗号。
xxxxxxxxxx
<update id="update" parameterType="com.itbaizhan.user.User">
update user
<set>
<if test="username != null and username.length() > 0">
username = #{username},
</if>
<if test="sex != null and sex.length() > 0">
sex = #{sex},
</if>
</set>
<where>
id = #{id}
</where>
</update>
1.MyBatis映射文件中,<where>
的作用是:
A 代替sql中的where
B 代替sql中的where 1=1
C 代替sql中的第一个and
D 代替sql中的where 1=1和第一个and
2.MyBatis映射文件中,<set>
的作用是:
A 添加set关键字
B 去掉最后一个if语句中多余的逗号
C 自动添加set关键字,并去掉最后一个if语句中多余的逗号
D 没有作用
1=>D 2=>C