STUDY/DBMS
[MyBatis] MyBatis에서 insert 쿼리 등을 여러개 실행시키는 법
nnh
2023. 4. 11. 11:43
728x90
하나의 MyBatis 에서 여러개의 쿼리를 실행시키고 싶을 때가 있다.
이때 DB연결 부분에서 allowMultiQueries=true 를 붙여주면 된다.
jdbc:mysql://localhost:3306/test?allowMultiQueries=true
아래는 이를 이용해 한번에 여러개의 insert 쿼리를 실행하는 MyBatis 코드다.
<insert id="insertTestValue" parameterType="com.test.testCode.main.testClass.dto.request.testReqDto">
insert into testTable2(
id,
seq,
age,
name
)
select
tt.id,
pt.seq,
#{age},
#{name}
from testTable tt
inner join personTable pt
on pt.age = tt.age
where tt.age = #{age}
and tt.deleted_at is null
order by pt.seq
</insert>
728x90