์์ ๊ฐ์ด insert๋ฅผ 1๊ฐ ์ด์ ํ๋ ๋ก์ง์ ๋ง๋ค๊ฒ ๋์๊ณ ๋ฏธ๋์ ๋ด๊ฐ ๋ณด๊ธฐ ์ํด ๊ธฐ๋กํ๋ค. ๐
ํด๋ผ์ด์ธํธ์์ ๋ฐฐ์ด๋ก ๊ฐ์ ๋ฐ์์ DB์ ์ ์ฅํ๋ ๊ธฐ๋ฅ์ด ํ์ํ๋ค.
์ฐธ๊ณ ๋ก mysql๊ณผ Oracle์ ๋ฌธ๋ฒ์ด ๋ค๋ฅด๋ค.
Oracle์ ์์ง ์ํด๋ด์ ๊ทธ๊ฑด ๋์ค์ ์์๋ณด๊ฒ ๋ค.
Controller
@RequestParam(value = "๋ณ์๋ช []") String[] avengers ์ด๋ฐ์์ผ๋ก ๋ฐ์
@PostMapping("")
public ResponseEntity<?> createArray(
@RequestParam(value = "avengers[]") String[] avengers
) throws Exception{
Service.insertAvengers(avengers);
์๋ต...
Service
public void insertAvengers(String[] avengers) throws Exception {
Mapper.insertAvengers(avengers);
}
Mapper
public void insertAvengers(String[] avengers);
xml
๋ฐฐ์ด๋ก ๋๊ฒผ์ผ๋ฉด ๋ฐ๋์ collection์ "array"๋ก ํ ๊ฒ
<insert id="insertAvengers">
INSERT INTO avengers
(
hero_name,
reg_date
)
VALUES
<foreach collection="array" item="item" separator=",">
(
#{item},
NOW()
)
</foreach>
</insert>
๊ฐ์ธ ์คํฐ๋ ๊ธฐ๋ก์ ๋ฉ๋ชจํ๋ ๊ณต๊ฐ์ด๋ผ ํ๋ฆฐ์ ์ด ์์ ์ ์์ต๋๋ค.
ํ๋ฆฐ ์ ์์ ๊ฒฝ์ฐ ๋๊ธ ๋ถํ๋๋ฆฝ๋๋ค.
[mybatis] mybatis ๋์ ์ฟผ๋ฆฌ(feat. <where></where>)
๋ชฉ์ฐจ mybatis Dynamic SQL ๐ ๊ณ์ ์ค์ ํ๋ ๋์ ์ฟผ๋ฆฌ์ด๋ค. ์ค๋ ๋๋ ์ด๊ฑธ ์ดํด ํ์ง๋ง ๋ฏธ๋์ ๋ ๋ ๊น๋จน์ ์ ์์ผ๋ ์ฌ๊ธฐ์ ๋ฉ๋ชจํด ๋๋ค. ๋์ WHERE ํ์ ํ ์ด๋ธ์์ ํ์์ด๋ฆ๊ณผ ์ด๋ฉ์ผ์ ์กด์ฌ์
yaga.tistory.com
[mybatis] foreach parameterType hashmap ์์
๋ฏธ๋์ ๋๋ฅผ ์ํด ๊ธฐ๋กํ๋ค. ๐mybatis์์ foreach๋ฅผ ๋๋ฆด ๋ list๋ ์ด์ ์ข ์ต์ํด ์ก๋๋ฐ map์ ์์ง ์ข ์ํฐ ๋๋์ด ๋ค์ด ๊ธฐ๋กํ๋ค.์์ ๋ ๋์ ์ผ๋ก insert๋ฌธ์ ๋ด์ฉ๊ณผ SELECT๋ฌธ์ ๋ด์ฉ์ ์ฑ์ฐ๋ ์
yaga.tistory.com
[mybatis] mybatis parameter ์ฌ๋ฌ๊ฐ ์ ๋ฌ
๋ชฉ์ฐจ์๋ฅผ ๋ค์ด Stringํ์ ์ "status"์ Longํ์ ์ no, 2๊ฐ์ parameter๊ฐ์ ๋ฐ์์ ํ ์ด๋ธ ์ ๋ฐ์ดํธ ํ๋ ค๋ ๋ก์ง์ด ์์ ์ VO์งธ๋ก ๋๊ธฐ๊ธฐ์ ๋ญ๊ฐ ๋นํจ์จ์ ์ด๊ณ ๋ค๋ฅธ์ฌ๋์ด ์ฝ๋๋ฅผ ๋ดค์ ๋๋ ์ง๊ด์ ์ด
yaga.tistory.com
'IT > development' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring data JPA] ์ด๊ฐ๋จ CRUD (0) | 2022.11.21 |
---|---|
[jpa] querydsl ์ธํ (feat. ํ๊ฒฝ์ค์ ๋ง ๋ค๋ฃธ) (1) | 2022.11.21 |
[mybatis] mybatis ๋์ ์ฟผ๋ฆฌ(feat. <where></where>) (0) | 2022.11.20 |
[mybatis] foreach parameterType hashmap ์์ (54) | 2022.11.20 |
[jQuery]radio/checkbox ์ฒดํฌ ์ฌ๋ถ ํ์ธ (0) | 2022.11.19 |
๋๊ธ