์ข ๋ฅ
- ์ ์ ์ปจํ ์ธ : ์๋ฒ์์ ํ๋ ๊ฒ ์์ด ํ์ผ์ ๊ทธ๋๋ก ๋ณด๋ด์ฃผ๋ ๊ฒ
- MVC์ ํ ํ๋ฆฟ ์์ง : jsp php์ฒ๋ฆผ html์ ๊ทธ๋ฅ ์ฃผ๋ ๊ฒ์ด ์๋ ๋์ ์ผ๋ก ๋ฐ๊ฟ์ ์ฃผ๋ ๊ฒ
- API : json์ด๋ ๋ฐ์ดํฐ ํฌ๋งท์ผ๋ก ํด๋ผ์ด์ธํธ์๊ฒ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌ, ํ๋ฉด์ ํ๋ก ํธ๊ฐ ์์์
์ ์ ์ปจํ ์ธ
๊ธฐ๋ณธ์ ์ผ๋ก Spring์ static ํด๋์์ ์ ์ ์ปจํ ์ธ ๋ฅผ ์ฐพ์ ์ ๊ณต
ex) static ํด๋์ hello-static.html ํ์ผ์ ๋ฃ์ผ๋ฉด localhost:8080 /hello-static.html ์ฃผ์๋ก ๋งคํ๋จ
- localhost:8080/hello-static.html ์์ฒญ
- ๋ด์ฅ ํฐ์บฃ ์๋ฒ๊ฐ ์คํ๋ง ์ปจํ ์ด๋๋ก ์์ฒญ ์ ๋ฌ
- ์ปจํ ์ด๋๊ฐ controller ํ์ธ
- "hello-static"๊ด๋ จ ์ปจํธ๋กค๋ฌ๊ฐ ์์์ resources ํ์ธ (๋ด์ฅ ํฐ์บฃ ์๋ฒ)
- resources/static/hello-static.html ์ ์ฐพ์ ๊ทธ๋๋ก ์น๋ธ๋ผ์ฐ์ ์ ์ ๋ฌ
MVC์ ํ ํ๋ฆฟ ์์ง
MVC๋?
- model : ํ๋ฉด์ ํ์ํ ๋ฐ์ดํฐ๋ค์ ๋ด์์ view์ ๋๊ฒจ์ค
- view : ํ๋ฉด(front)์ ์ง์ค
- controller : ๋ด๋ถ ๋ก์ง
- localhost:8080/hello-mvc ์์ฒญ
- ๋ด์ฅ ํฐ์บฃ ์๋ฒ๊ฐ ์คํ๋ง ์ปจํ ์ด๋๋ก ์์ฒญ ์ ๋ฌ
- controller์์ "hello-mvc"๋ฅผ ์ฐพ์ ์คํ
- viewResolver๋ก ์ฐ๊ฒฐ (return: hello-template / model(name:spring))
- viewResolver์์ templatesํด๋ ์์ "hello-template"ํ ํ๋ฆฟ์ ์ฐพ์ html๋ก ๋ ๋๋ง (์ด๋ ๋์ ๋ฐ์ดํฐ๊ฐ ๋ฐ์)
- html ํ์ผ์ ์น ๋ธ๋ฌ์ฐ์ ธ์ ์ ๋ฌ
API ๋ฐฉ์
- localhost:8080/hello-api ๋ก ์์ฒญ
- ๋ด์ฅ ํฐ์บฃ ์๋ฒ๊ฐ ์คํ๋ง ์ปจํ ์ด๋๋ก ์์ฒญ ์ ๋ฌ
- controller์์ "hello-api"๋ฅผ ์ฐพ์ ์คํ
- @ResponseBody ์ด๋ ธํ ์ด์ ์ด ์๋ ๊ฒฝ์ฐ http์ body์ ๋ด์ฉ์ ์ง์ ๋ฐํ
- HttpMessageConverter๋ก json์ผ๋ก ๋ณํ
๊ฐ์ฒด๋ผ๋ฉด MappingJackson2HttpMessageConverter
๋ฌธ์๋ผ๋ฉด StringHttpMessageConverter - json ํ์์ผ๋ก ์น๋ธ๋ผ์ฐ์ ์ ๋ฐํ
๋ฐ์ํ
'๊ฐ๋ฐ > Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JDBC Templete + PostgreSql ERROR (Can't infer the SQL type to use for an instance of java.util.ArrayList.) (0) | 2022.05.09 |
---|---|
domain, entity, dao, dto, vo ?? (0) | 2022.05.06 |
Spring ํ๋ก์ ํธ ์์ฑ (Gradle) (0) | 2022.03.03 |
ZonedDateTime (UTC -> KST) (0) | 2022.02.23 |
Spring ํตํฉ ํ ์คํธ - JUnit5 (0) | 2022.02.21 |