1.Spring-mybatis-动态SQL-foreach标签
This commit is contained in:
@@ -61,4 +61,8 @@ public interface EmpMapper {
|
||||
/*@Select("select * from emp where name like concat('%',#{name},'%') and gender = #{gender}" +
|
||||
" and entrydate between #{begin} and #{end} order by update_time desc ;")*/
|
||||
public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);
|
||||
|
||||
|
||||
//批量删除
|
||||
public void deleteByIds(List<Integer> ids);
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.inmind.mapper.EmpMapper">
|
||||
|
||||
<!--条件查询操作-->
|
||||
<select id="list" resultType="com.inmind.pojo.Emp">
|
||||
select * from emp
|
||||
@@ -53,4 +52,21 @@
|
||||
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
<!--
|
||||
批量删除
|
||||
collection:遍历的集合(接口方法中传入的参数名)
|
||||
item:集合遍历出来的元素
|
||||
separator:分隔符,每个元素之间用什么符号相连
|
||||
open:遍历开始之前拼接的sql片段
|
||||
close:遍历结束之前拼接的sql片段
|
||||
-->
|
||||
<delete id="deleteByIds">
|
||||
<!-- delete from emp where id in (17,18);-->
|
||||
delete from emp where id in
|
||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
@@ -8,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@@ -90,4 +91,9 @@ class SpringbootMybatisCrudApplicationTests {
|
||||
emp.setUpdateTime(LocalDateTime.now());
|
||||
empMapper.update(emp);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteByIds(){
|
||||
empMapper.deleteByIds(Arrays.asList(19,20,21));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user