๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“– Java&Spring

HTTP Query Parameter์—์„œ Arrary List ์‚ฌ์šฉ

API ์„ค๊ณ„ํ•  ๋•Œ, GET์„ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„์˜ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜๊ณ  ์‹ถ์€๋ฐ, ๋ฒ”์œ„๊ฐ€ ํ•„์š”ํ•œ ๊ฐ’๋“ค์ด ์žˆ๋‹ค.

Query Paramter์— Array๋„ ๊ฐ€๋Šฅํ•˜๊ณ  Json Type๋„ ์“ธ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ชจ๋ฅธ๋‹ค๋ฉด POST ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Body ๋ฉ”์ง€์‹œ์— ๋ฒ”์œ„ ๊ฐ’์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฑธ๋กœ ์„ค๊ณ„ํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค๋ฉด,

POST /bell/v2/list HTTP/1.1
...
{
    "list":[0, 5]
}


๋ฌผ๋ก  ์ด ๋ฐฉ์‹๋„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทผ๋ฐ Resource URI๋ฅผ ๋” ๊ณ ๋ฏผํ•ด์•ผํ•˜๋Š”;; ์ƒํ™ฉ์— ๋†“์ด๊ฒŒ ๋œ๋‹ค
GET์—๋„ body ๋ฉ”์‹œ์ง€๋ฅผ ๋ฌผ๋ก  ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋‹ค. ๊ทผ๋ฐ GET ๋ฉ”์†Œ๋“œ์— ๋Œ€ํ•ด์„œ๋Š” body๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š๋Š” ์„œ๋ฒ„๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ†ต์ƒ์ ์ธ? ํ‘œํ˜„์€ ์•„๋‹Œ ๋“ฏ ํ•˜๋‹ค.
๊ทธ๋ž˜์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ณด๋‚ด๋ฉด ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐ๋œ๋‹ค.

GET /bell/v2/list?type=0&type=5&name=test HTTP/1.1
...


Spring์—์„œ๋Š” Query์— ๋“ค์–ด์˜จ Array์— ๋Œ€ํ•ด์„œ๋„ ์•Œ์•„์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์„œ๋ฒ„ ์ž…์žฅ์—์„œ๋„ ์–ด๋ ค์šธ๊ฒŒ ์—†๋‹ค.

'๐Ÿ“– Java&Spring' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

@JsonProperty์™€ @JsonNaming  (0) 2023.03.17
Java์˜ Hash ์•Œ๊ณ ๋ฆฌ์ฆ˜ MessageDigest  (0) 2023.03.16
Spring Cron Expression  (0) 2023.01.25
StringUtils  (0) 2023.01.18
Looking For Annotation~  (0) 2023.01.16