Mybatis에서 여러 개의 Update문을 한 번에 수행하는 방법기록 (MySql)
그전에 <foreach> 태그를 사용한 케이스는 크게 두 가지였고, 아래 케이스들은 쿼리문안에서의 반복이었기 때문에 문제없이 수행되었다.
// 1. in절
...
AND a.auth IN
<foreach collection="authorities" item="item" index="i" open="(" separator="," close=")">
#{item}
</foreach>
...
// 2. insert문
<insert id="insertTemp" parameterType="tempVO">
INSERT INTO temp
(temp_id
, col1
, col2
, col3)
VALUES
<foreach collection="temps" item="temp" separator=",">
(#{temp_id}
, #{col1}
, #{col2}
, #{col3})
</foreach>
</insert>
내가 하고 싶은 건 update문 자체를 한 번에 여러 개 만들어 수행하는 것이었음
1. 일단 아래처럼 update문을 foreach로 반복해서 만들어서 수행해 보았다
<update id="updateOrder" parameterType="UpdateOrderRequestVO">
<foreach collection="request" item="request" separator=";">
UPDATE order m
SET m.sort_order = #{request.sortOrder}
WHERE m.member_id = #{memberId}
AND m.order_id = #{request.orderId}
</foreach>
</update>
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near.....
에러가 빡🧐
로그에서 수행된 쿼리를 보면 문법오류 따위는 없는뎅 ㅎ
2. jdbc 설정에 allowMultiQueries=true를 설정하란다
구글 스승이 말해줌 'how to 어쩌고' '어쩌고 not working' 없이는 개발 못해
소스에서 application.yml 파일을 바로 열어서 org.mariadb.jdbc.Driver을 찾아 url 끝에 allowMultiQueries=true를 추가해 줬다.
그랬더니 아주 잘 굴러감 🥴
'개발기록 > Spring Boot' 카테고리의 다른 글
Spring Boot에서 Request 이력 저장하기 (0) | 2023.01.09 |
---|
댓글