/*
该XML定义了一个名为deleteBatch的删除操作,功能是从user表中批量删除指定主键(uid)的记录。具体功能如下:
使用foreach循环遍历传入的uids集合;
生成SQL语句中的IN子句参数;
实现批量删除功能。
*/
<delete id="deleteBatch">
delete from user
<where>
uid in
<foreach collection="uids" open="(" close=")" separator="," item="uid">
#{uid}
</foreach>
</where>
</delete>
/*
解释:
该XML片段定义了一个名为insertBatch的插入操作,功能是批量插入用户数据。主要特点如下:
插入目标表为user。
使用foreach标签遍历传入的userList集合。
为每个user对象生成一条插入记录,各记录间用逗号分隔。
每条记录包含用户ID、用户名、密码、邮箱、电话、生日、性别和角色等字段。
*/
<insert id="insertBatch">
insert into user values
<foreach collection="userList" item="user" separator=",">
(#{user.uid},#{user.username},
#{user.password},#{user.email},#{user.telephone},
#{user.birthday},#{user.sex},#{user.role})
</foreach>
</insert>
/*
此XML片段定义了一个名为findUserListByCondition的SQL查询,功能是从user表中根据条件筛选用户列表。具体如下:
选择指定列(列名通过user_colums引用)。
如果username不为空,则进行模糊匹配。
如果email不为空,则精确匹配。
如果telephone不为空,则精确匹配
*/
<select id="findUserListByCondition" resultType="edu.hevttc.domain.User">
select <include refid="user_colums"></include>
from user
<where>
<if test="username != null and username != ''">
username like concat('%',#{username},'%')
</if>
<if test="email != null and email != ''">
and email=#{email}
</if>
<if test="telephone != null and telephone != ''">
and telephone=#{telephone}
</if>
</where>
</select>