2024/03/11
今日学习web时长一小时
代码行数大概100多行
博客数量一篇
今天主要完成了通过xml配置文件完成了数据的批量删除和根据指定字段查询
关键的应用标签就是<where><if>来完成指定字段的SQL语句的成立与否
<foreach>来完成不定个数主键来删除数据
// 利用xml来完成条件查询
public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);
/*根据id来完成单个或批量删除员工*/
void delete(List<Integer> ids);
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.tlias.mapper.EmpMapper">
<update id="update">
update emp
<set>
<if test="name!=null">
username=#{username},
</if>
<if test="password!=null">
password=#{password},
</if>
<if test="name!=null">
name=#{name},
</if>
<if test="gender!=null">
gender=#{gender},
</if>
<if test="image!=null">
image=#{image},
</if>
<if test="job!=null">
job=#{job},
</if>
<if test="entrydate!=null">
entrydate=#{entrydate},
</if>
<if test="deptId!=null">
dept_id=#{deptId},
</if>
<if test="updateTime!=null">
update_time=#{updateTime}
</if>
</set>
where id=#{id}
</update>
<select id="list" resultType="com.itheima.tlias.pojo.Emp">
select id,
username,
password,
name,
gender,
image,
job,
entrydate,
dept_id,
create_time,
update_time
from emp
<where>
<if test="name!=null and name!=''">
name like concat('%',#{name},'%')
</if>
<if test="gender!=null">
and gender=#{gender}
</if>
<if test="begin!=null and end !=null">
and entrydate between #{begin} and #{end}
</if>
</where>
order by update_time desc
</select>
<delete id="delete">
delete from emp where id in
<foreach collection="ids" separator="," close=")" open="(" item="id">
#{id}
</foreach>
</delete>
</mapper>
等


浙公网安备 33010602011771号