참조 : https://dskim-life.tistory.com/entry/mybatis-muliti-update-%ED%95%98%EB%A0%A4%EB%A9%B4
마이바티스로 foreach update하는데 계속 오류남.....
Error: 1241-21000: Operand should contain 1 column(s)
Error: 1064-42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near
?allowMultiQueries=true
도 잘 넣었음
일단 list를 map에 넣어서 mapper로 보냄
List<String> list
map.put("list",list);
list=[8, 9]
참고로 이렇게 생김
map : {gIdx=9, list=[8, 9]}
이전 : open="(" close=")" separator=","
수정한한 내용
parameterType="java.util.List"
open="" close="" separator=";"
<update id="updateCode" parameterType="java.util.List">
<foreach collection="list" item="mIdx" open="" close="" separator=";" >
UPDATE tb
SET
g_idx = #{gIdx}
WHERE
m_idx = #{mIdx}
</foreach>
</update>
item="mIdx" 은 item="item"이라도 잘 되었음
<insert id="insert" parameterType="java.util.List">
INSERT INTO tb
(
num,
regist_dt
)
VALUES
<foreach collection="list" item="num" open="" close="" separator=" , ">
(
#{num},
now()
)
</foreach>
</insert>