<select id="selectByUser" parameterType="SysUser"resultMap="userMap">
select
<includerefid="userSql"/>
from sys_user
<where>
1=1
<iftest="userName !=null and userName !=''">
and user_name like concat('%',#{userName},'%')
</if><iftest="userEmail !=null and userEmail !=''">
and user_email=#{userEmail}
</if></where></select>
<insertid="insertByIdIf"parameterType="SysUser">
insert into sys_user
(user_name,user_password,
<iftest="userEmail !=null and userEmail !=''">user_email,</if>
user_info,head_img,create_time)
values
(#{userName},#{userPassword},
<iftest="userEmail !=null and userEmail !=''">#{userEmail},</if>
#{userInfo},#{headImg,jdbcType=BLOB},#{createTime,jdbcType=TIMESTAMP})
</insert>
choose标签
一个choose 中至少有一个when,有0个或1个otherwise
<select id="selectByidOrUserName" parameterType="SysUser"resultMap="userMap">
select
<includerefid="userSql"/>
from sys_user
<where>
1=1
<choose><whentest="id !=null">
and id=#{id}
</when><whentest="userName !=null and userName !=''">
and user_name =#{userName}
</when><otherwise>
and 1=2
</otherwise></choose></where></select>
<iftest="userName!=null and userName!=''"><bindname="userNameLike"value="'%'+userName+'%'"/>
and user_name like #{userNameLike}
</if>
_databaseId 判断数据库类型
<select id="selectByUser" parameterType="SysUser"resultMap="userMap">
select
<includerefid="userSql"/>
from sys_user
<where>
1=1
<iftest="userName !=null and userName !=''"><iftest="_databaseId=='mysql'">
and user_name like concat('%',#{userName},'%')
</if><iftest="_databaseId=='oracle'">
and user_name like '%'||#{userName}||'%'
</if></if><iftest="userEmail !=null and userEmail !=''">
and user_email=#{userEmail}
</if></where></select>