Java Spring17 [Spring]๋จ์ํ ์คํธ jUnit ๋ชฉ์ฐจ ๋จ์ํ ์คํธ jUnit ๊ฐ๋ฐํ๊ธฐ์ ์๋์ ๊ฐ์ด jUnit์ผ๋ก JDBC Connection์ ๋จผ์ ํ๊ณ ์์ํ๋ ์ต๊ด์ ๊ธฐ๋ฅผ ๊ฒ ๋จ์ํ ์คํธ ํ๊ธฐ ์ํด ๋งค๋ฒ Tomcat์ ์คํํ์ง ์๊ณ ๋ jUnit ํ ์คํธ ๋๊ตฌ๋ฅผ ์ด์ฉํด์ Tomcat ์คํ ์์ด springFramework๋ฅผ ๊ตฌ๋์์ผ์ DB Connection, CRUD๋ฑ์ ํ ์คํธ๊ฐ ๊ฐ๋ฅํด์ ์๊ฐ๋ ์ ์ฝ๋๊ณ ๋งค์ฐ ํจ์จ์ ์ด๋ฏ๋ก ๊ฐ๋ฐ ์์ ํญ์ ์์ฑํ๋ ์ต๊ด์ ๊ธฐ๋ฅด๋๋ก ํ์ ์คํ๋ง5 ๋ฒ์ ์ ๊ฒฝ์ฐ pom.xml์์ jUnit ๋ฒ์ ์ 4.12 ์ด์์ผ๋ก ํด์ผ ํ๋ค๊ณ ํจ ์๋๋ HikariCP๋ฅผ ์ด์ฉํ Connection Pool Test ์์ ์ด๋ฏธ์ง์ @RunWith, @ContextConfiguration ํด๋์ค ์๋จ์ ์ด๋ ธํ ์ด์ ๋ฑ์ ์ฌ์ฉํด์ ์ค์ ํ๊ณ jUnit.. IT/development 2022. 11. 27. [Spring]spring 404 ์๋ฌ ํ์ด์ง ์ฒ๋ฆฌ ๋ชฉ์ฐจ spring 404 ์๋ฌ ํ์ด์ง ์ฒ๋ฆฌ WAS์ ๊ตฌ๋ ์ค ๊ฐ์ฅ ํํ ์๋ฌ์ ๊ด๋ จ๋ HTTP ์ํ์ฝ๋๋ '404'์ '500' ์๋ฌ์ฝ๋ ์ 500 ๋ฉ์์ง๋ 'Internal Server Error'์ด๋ฏ๋ก @ExceptionHandler๋ฅผ ์ด์ฉํด์ ์ฒ๋ฆฌ๋์ง๋ง, ์๋ชป๋ URL์ ํธ์ถํ ๋ ๋ณด์ด๋ 404 ์๋ฌ ๋ฉ์์ง์ ๊ฒฝ์ฐ๋ ์กฐ๊ธ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์ ์๋ธ๋ฆฟ์ด๋ jsp๋ฅผ ์ด์ฉํ๋ ๊ฐ๋ฐ ์์๋ web.xml์ ์ด์ฉํด์ ๋ณ๋์ ์๋ฌ ํ์ด์ง๋ฅผ ์ง์ ํ ์ ์์์, ์๋ฌ ๋ฐ์ ์ ์ถ๊ฐ์ ์ธ ์์ ์ ํ๊ธฐ๋ ์ด๋ ต๊ธฐ ๋๋ฌธ์ ์คํ๋ง์ ์ด์ฉํด์ 404์ ๊ฐ์ด WAS ๋ด๋ถ์์ ๋ฐ์ํ๋ ์๋ฌ๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ์์ ์์๋๋ ๊ฒ์ด ์ข์ ์คํ๋ง MVC์ ๋ชจ๋ ์์ฒญ์ DispatcherServlet์ ์ด์ฉํด์ ์ฒ๋ฆฌ๋๋ฏ๋ก 404 ์๋ฌ๋ .. IT/development 2022. 11. 27. [Spring]spring RedirectAttribute ๋ชฉ์ฐจ spring RedirectAttribute Model ํ์ ๊ณผ ๋๋ถ์ด์ ์คํ๋ง MVC๊ฐ ์๋์ผ๋ก ์ ๋ฌํด ์ฃผ๋ ํ์ ์ค์๋ RedirectAttribute ํ์ ์ด ์กด์ฌํจ RedirectAttribute๋ ์กฐ๊ธ ํน๋ณํ๊ฒ๋ ์ผํ์ฑ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ๋ ์ฉ๋๋ก ์ฌ์ฉ๋จ RedirectAttribute๋ ๊ธฐ์กด์ Servlet์์ response.sendRedirect()๋ฅผ ์ฌ์ฉํ ๋์ ๋์ผํ ์ฉ๋๋ก ์ฌ์ฉ๋จ ์๋ ์ด๋ฏธ์ง์ฒ๋ผ RedirectAttribute๋ Model๊ณผ ๊ฐ์ด parameter๋ก ์ ์ธํด์ ์ฌ์ฉํ๊ณ addFlashAttribute(์ด๋ฆ, ๊ฐ) ๋ฉ์๋๋ฅผ ์ด์ฉํด์ ํ๋ฉด์ ํ๋ฒ๋ง ์ฌ์ฉํ๊ณ ๋ค์์๋ ์ฌ์ฉํ์ง ์๋ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ๊ธฐ ์ํด์ ์ฌ์ฉ๋จ ์ถ์ฒ: ์ฝ๋๋ก ๋ฐฐ์ฐ๋ ์คํ๋ง ์น ํ๋ก์ ํธ(๊ฐ์ ํ) IT/development 2022. 11. 27. [Spring]springframework Controller ๋ชฉ์ฐจ Spring Controller spring controller์ paramter ์์ง Controller๋ฅผ ์์ฑํ ๋ ๊ฐ์ฅ ํธ๋ฆฌํ ๊ธฐ๋ฅ์ parameter๊ฐ ์๋์ผ๋ก ์์ง๋๋ ๊ธฐ๋ฅ์, ์ด ๊ธฐ๋ฅ์ ์ด์ฉํ๋ฉด ๋งค๋ฒ request.getParameter()๋ฅผ ์ด์ฉํ๋ ๋ถํธํจ์ ์์จ ์ ์์ ์์ ๊ฐ์ด SampleDTO class๊ฐ ์๊ณ (Lombok ์ฌ์ฉ์ผ๋ก @Data ์ด๋ ธํ ์ด์ ์ผ๋ก ์๋์ผ๋ก setter, getter, toString method ์์ฑ) ์์ ๊ฐ์ด SampleController์ method๊ฐ SampleDTO๋ฅผ parameter๋ก ์ฌ์ฉํ๊ฒ ๋๋ฉด ์๋์ผ๋ก setter ๋ฉ์๋๊ฐ ๋์ํ๋ฉด์ parameter๋ฅผ ์์งํ๊ฒ ๋จ method์๋ @GetMapping์ด ์ฌ์ฉ๋์์ผ๋ฏ๋ก, ์๋์ ๊ฐ์ด ๋ธ.. IT/development 2022. 11. 27. [Spring]pom.xml์์ dependency ์ค์ ํด ์คฌ๋๋ฐ ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ค์ด์ด ์๋๋ ๊ฒฝ์ฐ ๋ชฉ์ฐจ ๋ณดํต ๋ก์ปฌ repository์์ ๋ด์ฉ์ ์ง์ฐ๊ณ ๋ค์ ๋ค์ด์ ๋ฐ๊ฑฐ๋ ํ๋ ๋ฐฉ์์ผ๋ก ํด๊ฒฐ์ด ๋๋๋ฐ ํ๋คํ๋ค ์๋๋ฉด maven์์ ์ฐธ์กฐ๋ฅผ ๋ชปํ๋ .jarํ์ผ์ "ํ๋ก์ ํธ/src/main/webapp/WEB-INF/lib ๋๋ ํฐ๋ฆฌ์ ๋ฃ๊ณ pom.xml์์ propertiesํ๊ทธ์ ์๋์ฒ๋ผ jarํ์ผ์ ๋ฃ์ lib๋๋ ํฐ๋ฆฌ๋ฅผ ์ค์ ํด์ค 4.2.4.RELEASE 3.7.0 ${project.basedir}/src/main/webapp/WEB-INF/lib ๊ทธ ๋ค์ dependency๋ฅผ ํด๋น lib๋๋ ํฐ๋ฆฌ์ jar๋ก ์ค์ org.springframework.webmvc org.springframework.webmvc-4.2.4 4.2.4 system ${project.lib.path}/spring-webmvc-.. IT/development 2022. 11. 26. [Spring]์คํ๋ง ํ๋ก์ ํธ ์ดํด๋ฆฝ์ค์์ ํ๋ก์ ํธ๋ช ๋ณ๊ฒฝ ์ tomcat ์๋ฌ ๋ชฉ์ฐจ web.xml์ ํ๊ทธ๋ช ์ด ๋ณ๊ฒฝ๋์ด์ ์๋ฌ ๋๋ ๊ฒฝ์ฐ ๋ก๊ทธ๋ ์๋์ ๋น์ทํจ..๋ก๊ทธ๋ฅผ ๋ณด๋..์ด๋ฏธ ์ ์๋์ด ์๋ค๊ณ ํ๋ค. ์์ธ์ ์๋์ ๊ฐ์ด web.xml์ xmlns๊ฐ ์ค๋ณต๋์ด ์์์ ๊ทธ๋ฆฌ๊ณ web.xml์๋จ์ web-app์์ ์ด๋ฏธ id๊ฐ๋ ์ค์ ํ๊ธฐ์ ์ ์ผ ๋ง์ง๋ง ์ค์ id๋ ์ญ์ ๋ฅผ ํด์ผ ์ ์์ ์ผ๋ก tomcat์ ๊ตฌ๋ํ ์ ์์ IT/development 2022. 11. 26. [springBoot] ์ ํจ์ฑ ๊ฒ์ฆ(feat. @Valid, Validated) ๋ชฉ์ฐจ SpringBoot ์ ํจ์ฑ ๊ฒ์ฆ ๐ ํด๋ผ์ด์ธํธ์์ ๋์ด์จ ๊ฐ๋ค์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ์ด ํ์ํ๋ฐ if(id != null || id != ""...) ์ด๋ ๊ฒ if๋ฌธ์ผ๋ก ์ ํจ์ฑ ์ฒดํฌ๋ฅผ ํ๊ธฐ ์ซ์ด์ ์๋ฐ๋ ์คํ๋ง์์ ์ง์ํ๋ ์ข์๊ฒ ์ด๋ ์๋ ๋ณด๋ค๊ฐ ๊ตฌ๊ธ๋ง์ ํ๊ณ @Valid์ @Validated๋ฅผ ์๊ฒ๋์ด์ ์ ์ฉ์ ํด๋ดค๊ณ ์ด๋ฅผ ๊ธฐ๋กํ๋ค. ๋ "", " ", null ์ด๋ ๊ฒ 3๊ฐ๋ง ์ฒดํฌํ๋ฉด ๋๋ ๋ถ๋ถ์ด์๋ค. ๊ฒฐ๋ก ์ ์คํ๋ง๋ถํธ์์ @Valid์ @Validated 2๊ฐ๋ฅผ ์ฌ์ฉํด์ ๊ฐ๋จํ ์ ํจ์ฑ ์ฒดํฌ๋ฅผ ํ ์ ์์ @Valid ๐ฅฐ @Valid๋ JSR-303 Bean Validator๋ฅผ ์ด์ฉํด์ ์ ํจ์ฑ์ ์ฒดํฌํ๋ ์ด๋ ธํ ์ด์ ์(์๋ฐ ํ์ค ์คํ) ์ฌ์ฉ๋ฒ ์คํ๋ง๋ถํธ ๋ฒ์ ์ ๋ฐ๋ฅธ ์์กด์ฑ ์ถ๊ฐ ์ฌ์ฉํ๋ ์คํ๋ง ๋ถํธ ๋ฒ.. IT/development 2022. 11. 22. ์ด์ 1 2 ๋ค์