spring6 [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. [mybatis] mybatis ๋์ ์ฟผ๋ฆฌ(feat. <where></where>) mybatis Dynamic SQL ๐๊ณ์ ์ค์ ํ๋ ๋์ ์ฟผ๋ฆฌ์ด๋ค.์ค๋ ๋๋ ์ด๊ฑธ ์ดํด ํ์ง๋ง ๋ฏธ๋์ ๋ ๋ ๊น๋จน์ ์ ์์ผ๋ ์ฌ๊ธฐ์ ๋ฉ๋ชจํด ๋๋ค.๋์ WHEREํ์ ํ ์ด๋ธ์์ ํ์์ด๋ฆ๊ณผ ์ด๋ฉ์ผ์ ์กด์ฌ์ ๋ฐ๋ผ ๋์ ์ผ๋ก WHERE์ ๋ถ์ฌ์ ๊ฒ์ํ๋ ์์์ด๋ค.๊ธฐ์กด์๋ mapper xml์์ ์๋์ฒ๋ผ ์์ฑํ์๋ค. ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ๊ณ ๋ ๋ฐ๋์ ๋จ์ ํ ์คํธ๋ฅผ ์ฌ๋ฌ๋ฒ ํด๋ด์ผ ํ๋ค๋ ๊ฑธ ๋ ๊นจ๋ฌ์๋ค.(๊ทธ๊ฑธ ์ด์ ์์๋? ๐ฅ) SELECT * FROM member WHERE member_name = #{memberName} WHERE email = #{email} ์ญ์ ๊ฐ๋ฐํ๋ฉด์ JUnit์ผ๋ก ๋จ์ ํ ์คํธ๋ฅผ ๊ณ์.. IT/development 2022. 11. 20. ์ด์ 1 ๋ค์