<!-- 条件查询--> <selectid="list"resultType="com.rc.springdemo1.pojo.Emp"> select * from emp <where> <iftest="name != null"> name like concat('%', #{name}, '%') </if> <iftest="name != null"> and gender = #{gender} </if> <iftest="name != null"> and entrydate between #{begin} and #{end} </if> </where> order by update_time desc </select>
foreach
1 2 3 4 5 6 7 8 9
<!-- 批量删除员工--> <deleteid="delete"> delete from emp where id in <foreachcollection="ids"item="id"separator=","open="("close=")"> #{id} </foreach> </delete>
collection
待遍历的内容,与参数名相同
item
遍历出来的对象,命名可自定义
separator
分隔符
open
开始前添加
close
结束后添加
注入对象 @Autowired
在 Service 中
1 2
@Autowired private DeptMapper deptMapper;
数据库操作
注解形式查询操作 @Select("")
在方法上注解 @Select("")
1 2 3 4 5 6
@Mapper publicinterfaceDeptMapper { @Select("select * from dept") List<Dept> list(); }