*Framework
- ์์ฃผ ์ฌ์ฉ๋ ๊ธฐ๋ฅ์ ๋ฏธ๋ฆฌ ๊ตฌํํด ๋์ ๊ฒ ( ์์ฐ์ฑ ํฅ์ )
- ๋ฐฐํฌ๋ .jar๋ก ์ํ (.class๋ง, war๋ class์ html,jsp๋ ๊ฐ์ด)
- ์ ๊ณต๋๋ ๊ธฐ๋ฅ์ ์ฌ์ฉ์์ ์ํฉ์ ๋ง๊ฒ ์์ ํ์ฌ ์ฌ์ฉํ๊ณ , ์๋ช
์ฃผ๊ธฐ์ ๊ด๋ฆฌ๋ฅผ ๊ฐ๋ฐ์๊ฐ ํ์ง ์์ (new ์ํจ)
- ๋ฐ ์กฐ๋ฆฝํํ
- ์ต์ํ์ ํ์ง ๋ณด์ฅ์ ๋ฐ๊ธฐ ์ํด ํ๋ ์์ํฌ๋ฅผ ๋์
- Spring, MyBatis, any framework,,,,
*Library
- ์์ฃผ ์ฌ์ฉ๋ ๊ธฐ๋ฅ์ ๋ฏธ๋ฆฌ ๊ตฌํํด ๋์ ๊ฒ ( ์์ฐ์ฑ ํฅ์ )
- ๋ฐฐํฌ๋ .jar๋ก ์ํ
- ์ ๊ณต๋๋ ๊ธฐ๋ฅ์ ๊ทธ๋๋ก ์ฌ์ฉํ๊ณ , ์๋ช
์ฃผ๊ธฐ๋ฅผ ๊ฐ๋ฐ์๊ฐ ๊ด๋ฆฌํจ
*Spring
- spring.io์์ ๋ฌด๋ฃ ์ ๊ณต
- Spring IoC(Inversion of Control)์์ Spring framework ์ผ๋ก ๋ณํ
- Spring DI, AOP, ORM, Web, MVC, JDBC ๋ฑ ๋ค์ํ ๊ธฐ๋ฅ์ ์ ๊ณต
*Spring MVC
- MVC Pattern์ ๋ฏธ๋ฆฌ ๊ตฌํํด์ ์ ๊ณตํ๋ Spring์ ๊ธฐ๋ฅ
- ์ค์ ํ์ผ ์์ด annotation์ ์ฌ์ฉํ์ฌ ๊ฐ๋จํ๊ฒ ์
๋ฌด๋ฅผ ์ฒ๋ฆฌํ ์ ์์ (์ฅ์ )
- DispatcherServlet์ Main Controller๋ก ์ฌ์ฉํจ - ๋ชจ๋ ์์ฒญ์ ๋ฐ๊ณ ์ฒ๋ฆฌ
์ด์ MVC์์๋ ์์ฒญ URL์ XxxAction ํด๋์ค ํ๋๊ฐ ์ฒ๋ฆฌํ์
http://localhost/a.do > ์ฒ๋ฆฌํ๊ธฐ ์ํด XxxAction ํด๋์ค ํ๋๊ฐ ํ์ํ์
์ ์ฌํ ์์
์ผ๋ก ํด๋์ค๋ฅผ ๊ด๋ฆฌํ๋ ค๋ฉด package๋ฅผ ๋ง๋ค์ด์ ๊ด๋ฆฌํด์ผํจ > ํจํค์ง ๊ฐ์๊ฐ ์ฆ๊ฐํจ
ex)
package user
package user.login
package user.myPage
Spring MVC์์๋ ์์ฒญ URL์ method ํ๋๊ฐ ์ฒ๋ฆฌํจ
http://localhost/a.do >url์ ์ฒ๋ฆฌํ๊ธฐ ์ํด XxxController.method() ํ๋๊ฐ ํ์ํจ
์ ์ฌํ ์์
์ ๊ด๋ฆฌํ๊ธฐ ์ํด์ Class๊ฐ ์์ฑ๋จ > ํจํค์ง ๊ฐ์๊ฐ ์ฆ๊ฐํ์ง ์์์ ๊ด๋ฆฌ๊ฐ ํธํจ
*DispatherServlet : ์ง์
์ , JSP๋ก ์ด๋, web.xml์ ๋ฑ๋ก์ด ๋์ด์ผ ํจ
*HandlerMapper : ์น์ ์์ฒญ์ด ๋ค์ด์ค๋ฉด ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์๋ Controller๋ฅผ ์ฐพ์์ ๋ฐํํ๋ ์ผ
*Controller : ์น์ ์์ฒญ์ ์ฒ๋ฆฌํ๋ ์ผ (์ค์)
*ViewResolver : ์๋ต์ ์ํํ๋ JSP๊ฐ ์กด์ฌํ๋์ง ์ถ์ ํ๋ ์ผ
*JSP : ํ๋ฉด์ ์ ์ํ์ฌ ๋ณด์ฌ์ฃผ๋ ์ผ
*Controller ์์ฑ๋ฒ
1. ํด๋์ค ์์ @Controller annotation์ ์ ์ธ //Handler Mapper๊ฐ Component-Scan์ ์ํ
HandlerMapper ํด๋์ค๊ฐ ๊ฒ์ํ๋ ํด๋์ค
์์ฒญ url์ ์ฒ๋ฆฌํ ๋ชฉ์ ์ ํด๋์ค
ํธ๋ค๋ฌ๋งคํผ๊ฐ ๊ฒ์ํ๊ฒ ํด์ฃผ๋ ค๋ฉด > @controller ํฐ๋ฅผ ๋ด์ค๋ค
์์ฒญ URL์ ๋ฉ์๋์์ ์ฒ๋ฆฌํ ์ ์๋๋ก annotation์ ์ค์
@Controller
public class Test{
2. method๋ฅผ ์ฌ์ฉํ์ฌ web์ ์์ฒญ ํ๋๋ฅผ ์ฒ๋ฆฌ
method์์ @RequestMapping annotation์ ์ฌ์ฉ
@RequestMapping( value=“/์์ฒญurl”, method=์์ฒญ๋ฐฉ์) //RequestMethod.GET, RequestMethod.POST
public String method๋ช
( ๋งค๊ฐ๋ณ์,,,, ){ //์ธ๋ถ์์ ๋ค์ด์ค๋ ์นํ๋ผ๋ฏธํฐ๋ฅผ ๋ฐ๊ธฐ ์ํด ์ ์
return “viewํ์ด์ง๋ช
”; //view๋ฅผ ํ JSP๋ช
(ViewResolver๊ฐ prefix์ suffix๋ฅผ ๋ถ์ฌ ์ฐพ์)
}
*POJO(Plain Old Java Object) ์ง์
- ํน์ ์ธ๋ถ ๊ธฐ์ ์ ํฌํจํ์ง ์๊ณ ์์ํ๊ฒ ์๋ฐ์์ ์ ๊ณตํ๋ ๋ฐ์ดํฐ ํ(๊ธฐ๋ฅ)๋ง ์ฌ์ฉํ์ฌ ์ ์ํ๋ ํด๋์ค
( ์คํ ๋ฐ ํ ์คํธ ์ฉ์ด์ฑ - ํ์บฃ ์์ด ๋ฉ์ธ ๋ฉ์๋๋ก ๋ฐ๋ก ์คํ)
/๋ก ๋ค์ด์ค๋ ๋ชจ๋ ์์ฒญ์ dispatcherServlet์ด ๋ฐ์
.do๋ก ๋ฐ๊ฟ์ฃผ๋ฉด html์ด๋ jsp๋ฅผ ์ง์ ์๋น์คํ ์ ์์
viewResolveํํ jsp๋ฅผ ์ฐพ๊ฒ ํจ
context:component-scan์ ๋ฒ ์ด์ค ํจํค์ง์ ๊ฐ์ ์ปดํฌ๋ํธ ์ค์บ์ ์ํํจ
*Spring MVC์ Controller(ํด๋์ค)๋ ํ๋์ ์์ ์ผ๋ก ๋ฌถ์ฌ์ง ์ ์๋ ์ธ๋ถ์์ ์ ์ ์
์) ๋ก๊ทธ์ธ ์ฒ๋ฆฌ
public class LoginController{
public String loginForm(){
}
public String loginProcess(LoginVO lv){
}
}//class
*Controller์์ method ์์ฒญ
//method << Web Client๊ฐ Web Server๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด๊ธฐ ์ํ ๋ฐฉ์์ ์ค์
@RequestMapping
: ์์ฒญ์ ์ฒ๋ฆฌํ method์์ ์ค์ , URL( URI )๋ก ์์ฒญ์ด ๋ฐ์ํ์ ๋ method๊ฐ ํธ์ถ๋์ด ์คํ๋จ
-GET๋ฐฉ์
@RequestMapping(value=“/URI”, method=RequestMethod.GET ) //URI:๋ด ์๋ฒ์์ ๋ค์ด์ค๋ ์์ฒญ๋ง ์ฒ๋ฆฌ
spring 5.x ์ด์์์๋ @GetMapping("URI")
public String method(){
-POST๋ฐฉ์
@RequestMapping(value=“/URI”, method=RequestMethod.POST )
@PostMapping("URI")
public String method(){
- GET| POST๋ฐฉ์ : ๋ฐฐ์ด์ ๋ฌธ๋ฒ์ ์ฌ์ฉ
//method๊ฐ get๋ฐฉ์, post๋ฐฉ์ ๋ชจ๋ ์ฒ๋ฆฌํ ์ ์๋๋ก ์ค์
@RequestMapping(value=“/URI”, method={RequestMethod.GET, RequestMethod.POST })
public String method()
{ ๋ฐฐ์ด ๊ธฐํธ๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ ๋ค๋ฅธ ์ด๋ฆ์ ์์ฒญ์ ํ๋์ method ์์ ์ฌ์ฉํ ์ ์์
*์์ฒญ์ ์ํด ํธ์ถ๋๋ method์ return ๊ฐ์ ๋ฐ์ ViewResolver ๊ฐ์ฒด๊ฐ ์๋ตํ์ด์ง๋ฅผ ์ฐพ์ ์คํํจ
public String method๋ช
(){
return “view๋ช
”
}
return ๋๋ ๊ฐ์ ViewResolver๊ฐ
์์ (prefix) /WEB-INF/views/ ๋ฅผ ๋ถ์ด๊ณ
๋ค์ ( suffix ) .jsp๋ฅผ ๋ถ์ฌ์ JSP๋ฅผ ์ฐพ์
์) “test”๊ฐ return ๋๋ ๊ฒฝ์ฐ
/WEB-INF/views/test.jsp๋ฅผ ์ฐพ์
*ํด๋์ค๋ค์ด์ด๊ทธ๋จ ์์ฑ
-Controller์ method๋ ์์ฒญURL ํ๋(์
๋ฌด ํ๋)๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ๋๋ฌธ์
Controller์ ์ด๋ฆ์ ์
๋ฌด๋ฅผ ์์ฐ๋ฅผ์ ์๋ ์ด๋ฆ์ผ๋ก ์ค์
- ๋งค๊ฐ๋ณ์ : web parameter๋ฅผ ๋ฐ๊ธฐ ์ํด ์กด์ฌ
- ๊ฐ์ด ํ๋ : ๋จ์ผํ
- ๊ฐ์ด ์ฌ๋ฌ ๊ฐ : VO
- ํ์ผ์ ๋ก๋ : HttpServletRequest
- View๋ก ๋ฐ์ดํฐ์ ๋ฌ : Model
- ์ธ์ ๋ฐ๊ธฐ : HttpSession
- ์ฟ ํค์ฌ๊ธฐ : HttpServletResponse
๋ฐํํ : String
์์ธ๊ฐ ๋ฐ์ํ ๊ฒ ๊ฐ์ผ๋ฉด ๋ฐํํ : ModelAndView