MVC ํ๋ ์์ํฌ ๋ง๋ค๊ธฐ
ํ๋ก ํธ ์ปจํธ๋กค๋ฌ ํจํด
ํ๋ก ํธ ์ปจํธ๋กค๋ฌ๋ ์๋ธ๋ฆฟ์ด๋ค.
์์ฒญ์ ๋ชจ๋ ๋ฐ๊ณ ์์ฒญ์ ๋ง๋ ์ปจํธ๋กค๋ฌ๋ฅผ ํธ์ถํ๋ค.
ํน์ง
ํ๋ก ํธ ์ปจํธ๋กค๋ฌ ์๋ธ๋ฆฟ ํ๋๋ก ํด๋ผ์ด์ธํธ์ ์์ฒญ์ ๋ฐ๊ณ , ์์ฒญ์ ๋ง๋ ์ปจํธ๋กค๋ฌ๋ฅผ ์ฐพ์์ ํธ์ถํ๋ค.
์
๊ตฌ๋ฅผ ํ๋๋ก ๋ฌถ๋๋ค.
ํ๋ก ํธ ์ปจํธ๋กค๋ฌ๋ฅผ ์ ์ธํ ๋๋จธ์ง ์ปจํธ๋กค๋ฌ๋ ์๋ธ๋ฆฟ์ ์ฌ์ฉํ์ง ์์๋ ๋๋ค.
์คํ๋ง ์น MVC์ ํ๋ก ํธ ์ปจํธ๋กค๋ฌ
์คํ๋ง ์น MVC์ ํต์ฌ๋ ๋ฐ๋ก FrontController์ด๋ค. (DispatcherServlet์ด ํ๋ก ํธ ์ปจํธ๋กค๋ฌ ํจํด์ผ๋ก ๋์ด์๋ค.)
ControllerV1์ ์ธํฐํ์ด์ค๋ก ๋ง๋ค๊ณ ์ด๋ฅผ ๊ตฌํํ Controller๋ค์ ๋ง๋ ๋ค.
public class MemberFormControllerV1 implements ControllerV1 {
@Override
public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String viewPath = "/WEB-INF/views/new-form.jsp";
RequestDispatcher requestDispatcher = request.getRequestDispatcher(viewPath); // ์ปจํธ๋กค๋ฌ์์ ๋ทฐ๋ก ์ด๋
requestDispatcher.forward(request, response); // ์๋ธ๋ฆฟ์์ JSP๋ฅผ ํธ์ถํ๋ค.
}
}
FrontControllerServletV1
@WebServlet(name = "frontControllerServletV1", urlPatterns = "/front-controller/v1/*")
public class FrontControllerServletV1 extends HttpServlet {
private Map<String, ControllerV1> controllerMap = new HashMap<>();
public FrontControllerServletV1(Map<String, ControllerV1> controllerMap) {
controllerMap.put("/front-controller/v1/members/new-form",
new MemberFormControllerV1());
controllerMap.put("/front-controller/v1/members/save",
new MemberSaveControllerV1());
controllerMap.put("/front-controller/v1/members",
new MemberListControllerV1());
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestURI = req.getRequestURI();
ControllerV1 controller = controllerMap.get(requestURI);
if (controller == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
controller.process(req, resp);
}
}
Controller ์ ๋ณด๋ฅผ ๊ฐ์ง ์๋ธ๋ฆฟ์ธ FrontContoller๋ฅผ ๊ตฌํํ๋ค.
- urlPatterns : โ/front-controller/v1/โ๋ฅผ ํฌํจํ ํ์ ๋ชจ๋ ์์ฒญ์ ํ๋์ ์๋ธ๋ฆฟ์์ ๋ฐ์๋ค์ธ๋ค.
- controllerMap : key-๋งคํ URL, value-ํธ์ถ๋ ์ปจํธ๋กค๋ฌ
- service() : reqeustURI๋ฅผ ์กฐํํ์ฌ ์ค์ ํธ์ถํ ์ปจํธ๋กค๋ฌ๋ฅผ ์ฐพ๊ณ ํด๋น ์ปจํธ๋กค๋ฌ๋ฅผ ์คํ(
process()
)ํ๋ค.
์ฌ๋ฌ Controller์ ์๋ธ๋ฆฟ์ด ํ๋์ JSP๋ฅผ ์ฌ์ฌ์ฉํ๊ณ ์๋ค.
View ๋ถ๋ฆฌ
Controller์์ View๋ก ์ด๋ํ๋ ๋ถ๋ถ์ด ์ค๋ณต๋๋ค.
Controller๋ MyView๋ง ๋ฐํํด์ฃผ๋ฉด ๋๋ค.
ControllerV2
public interface ControllerV2 {
MyView process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
}
- ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๋ฏ๋ก ๋ฐํ ํ์ ์ ๋ง์ถ ์ ์๋ค.
MyView
public class MyView {
private String viewPath;
public MyView(String viewPath) {
this.viewPath = viewPath;
}
public void render(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher(viewPath);
dispatcher.forward(request, response);
}
}
MemberFormControllerV2
public class MemberFormControllerV2 implements ControllerV2 {
@Override
public MyView process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
return new MyView("/WEB-INF/views/new-form.jsp");
}
}
- viewPath๋ฅผ ๊ฐ์ง๊ณ ์๋ MyView ๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ค.
FrontControllerServletV2
@WebServlet(name = "frontControllerServletV2", urlPatterns = "/front-controller/v2/*")
public class FrontControllerServletV2 extends HttpServlet {
private Map<String, ControllerV2> controllerMap = new HashMap<>();
public FrontControllerServletV2(Map<String, ControllerV2> controllerMap) {
controllerMap.put("/front-controller/v2/members/new-form",
new MemberFormControllerV2());
controllerMap.put("/front-controller/v2/members/save",
new MemberSaveControllerV2());
controllerMap.put("/front-controller/v2/members",
new MemberListControllerV2());
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestURI = req.getRequestURI();
ControllerV2 controller = controllerMap.get(requestURI);
if (controller == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
MyView view = controller.process(req, resp);
view.render(req, resp);
}
}
Model ์ถ๊ฐ
์๋ธ๋ฆฟ ์ข ์์ฑ ์ถ๊ฐ
์ปจํธ๋กค๋ฌ ์
์ฅ์์ HttpServletRequest
, HttpServletResponse
๊ฐ ํ์ํ์ง ์๋ค.
์์ฒญ ํ๋ผ๋ฏธํฐ๋ฅผ Map์ผ๋ก ๋๊ธฐ๋ฉด ์ปจํธ๋กค๋ฌ๊ฐ ์๋ธ๋ฆฟ์ด ์๋์ด๋ ๋์ํ ์ ์๋ค.
๋ทฐ ์ด๋ฆ ์ค๋ณต ์ ๊ฑฐ
ํ์ฌ ์ปจํธ๋กค๋ฌ์์ ์ง์ ํ๋ ๋ทฐ ์ด๋ฆ์๋ ์ค๋ณต(/WEB-INF/views/
)์ด ์กด์ฌํ๋ค.
์ปจํธ๋กค๋ฌ๋ ๋ทฐ์ ๋
ผ๋ฆฌ ์ด๋ฆ์ ๋ฐํํ๊ณ , ๋ฌผ๋ฆฌ ์ด๋ฆ์ ํ๋ก ํธ ์ปจํธ๋กค๋ฌ์์ ์ฒ๋ฆฌํ๋๋ก ๋ณ๊ฒฝํด๋ณด์.
๋
ผ๋ฆฌ์ ๋ฌผ๋ฆฌ์ ์ด๋ฆ์ ๊ตฌ๋ถํ๋ฉด ๋์ค์ ๋ณ๊ฒฝํ ๋ ์ปจํธ๋กค๋ฌ๋ฅผ ๋ณ๊ฒฝํ ์ผ์ด ์๋ค.
ModelView
Model์ ์ ๋ฌํ๊ธฐ ์ํด์ request.setAttribute()
๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๊ณ ๋ทฐ์ ์ ๋ฌํ๋ค.
์๋ธ๋ฆฟ์ ์ข
์์ฑ์ ์ ๊ฑฐํ๊ธฐ ์ํด, Model์ ๋ฐ๋ก ๋ง๋ค๊ณ View ์ด๋ฆ๊น์ง ์ ๋ฌํ๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ ๋ค.
public class ModelView {
private String viewName;
private Map<String, Object> model = new HashMap<>();
public ModelView(String viewName) {
this.viewName = viewName;
}
// ...
}
ControllerV3
public interface ControllerV3 {
ModelView process(Map<String, String> paramMap);
}
- ModelView๋ฅผ ๋ฐํํ๋๋ก ํ๋ค.
MemberSaveControllerV3
public class MemberSaveControllerV3 implements ControllerV3 {
private MemberRepository memberRepository = MemberRepository.getInstance();
@Override
public ModelView process(Map<String, String> paramMap) {
String username = paramMap.get("username");
int age = Integer.parseInt(paramMap.get("age"));
Member member = new Member(username, age);
memberRepository.save(member);
ModelView mv = new ModelView("save-result");
mv.getModel().put("member", member);
return mv;
}
}
- ๋ ผ๋ฆฌ ์ด๋ฆ์ ModelView ๊ฐ์ฒด์ ๋ฃ์ด ์์ฑํ๋๋ก ํ๋ค.
- ๋ชจ๋ธ์ ๋ทฐ์ ํ์ํ ๊ฐ์ฒด๋ฅผ ๋ด๊ณ ModelView ๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ค.
FrontControllerServletV3 ์ผ๋ถ
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestURI = req.getRequestURI();
ControllerV3 controller = controllerMap.get(requestURI);
if (controller == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
// param Map
Map<String, String> paramMap = createParamMap(req);
ModelView mv = controller.process(paramMap);
String viewName = mv.getViewName(); // ๋
ผ๋ฆฌ ์ด๋ฆ ex) new-form
MyView view = viewResolver(viewName);
view.render(mv.getModel(), req, resp);
}
private Map<String, String> createParamMap(HttpServletRequest req) {
Map<String, String> paramMap = new HashMap<>();
req.getParameterNames().asIterator()
.forEachRemaining(paramName -> paramMap.put(paramName, req.getParameter(paramName)));
return paramMap;
}
private MyView viewResolver(String viewName) {
MyView view = new MyView("/WEB-INF/views/" + viewName + ".jsp");
return view;
}
}
createParamMap()
: HttpServletRequest์ ํ๋ผ๋ฏธํฐ ์ ๋ณด๋ฅผ Map์ผ๋ก ๋ณ๊ฒฝํ๋ค.viewResolver()
: ์ปจํธ๋กค๋ฌ๊ฐ ๋ฐํํ ๋ ผ๋ฆฌ ๋ทฐ ์ด๋ฆ์ ์ค์ ๋ฌผ๋ฆฌ ๋ทฐ ๊ฒฝ๋ก๋ก ๋ณ๊ฒฝํ๋ค.view.render(mv.getModel(), req, resp)
: ๋ทฐ ๊ฐ์ฒด๋ฅผ ํตํด HTML ํ๋ฉด์ ๋ ๋๋งํ๋ค.
MyView
public void render(Map<String, Object> model, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
modelToRequestAttribute(model, req);
RequestDispatcher dispatcher = req.getRequestDispatcher(viewPath);
dispatcher.forward(req, resp);
}
๋จ์ํ๊ณ ์ค์ฉ์ ์ธ ์ปจํธ๋กค๋ฌ
์ปจํธ๋กค๋ฌ ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๋ฉด์ ํญ์ ModelView ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ๋ฐํํด์ผ ํ๋ ๋ถ๋ถ์ด ๋ฒ๊ฑฐ๋กญ๋ค.
์ปจํธ๋กค๋ฌ๋ View์ ์ด๋ฆ๋ง ๋ณ๊ฒฝํ๋๋ก, ์ค์ฉ์ฑ ์๋๋ก ๋ณ๊ฒฝํ๋ค.
ControllerV4
public interface ControllerV4 {
/**
*
* @param paramMap
* @param model
* @return viewName
*/
String process(Map<String, String> paramMap, Map<String, Object> model);
}
- view ์ด๋ฆ์ ๋ฐํํ๋๋ก ๋ณ๊ฒฝํ๋ค.
####
public class MemberSaveControllerV4 implements ControllerV4 {
private MemberRepository memberRepository = MemberRepository.getInstance();
@Override
public String process(Map<String, String> paramMap, Map<String, Object> model) {
String username = paramMap.get("username");
int age = Integer.parseInt(paramMap.get("age"));
Member member = new Member(username, age);
memberRepository.save(member);
model.put("member", member);
return "save-result";
}
}
- Controller์์๋ ํ์ํ ๊ฐ์ ๊บผ๋ด๊ณ , ๋น์ฆ๋์ค ๋ก์ง์ ํธ์ถํ ํ viewName๋ง์ ๋ฐํํ๋ค.
FrontControllerServletV4
@WebServlet(name = "frontControllerServletV4", urlPatterns = "/front-controller/v2/*")
public class FrontControllerServletV4 extends HttpServlet {
private Map<String, ControllerV4> controllerMap = new HashMap<>();
public FrontControllerServletV4(Map<String, ControllerV4> controllerMap) {
controllerMap.put("/front-controller/v2/members/new-form",
new MemberFormControllerV4());
controllerMap.put("/front-controller/v2/members/save",
new MemberSaveControllerV4());
controllerMap.put("/front-controller/v2/members",
new MemberListControllerV4());
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String requestURI = req.getRequestURI();
ControllerV4 controller = controllerMap.get(requestURI);
if (controller == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
// param Map
Map<String, String> paramMap = createParamMap(req);
// model
Map<String, Object> model = new HashMap<>();
String viewName = controller.process(paramMap, model);
MyView view = viewResolver(viewName);
view.render(model, req, resp);
}
private Map<String, String> createParamMap(HttpServletRequest req) {
Map<String, String> paramMap = new HashMap<>();
req.getParameterNames().asIterator()
.forEachRemaining(paramName -> paramMap.put(paramName, req.getParameter(paramName)));
return paramMap;
}
private MyView viewResolver(String viewName) {
MyView view = new MyView("/WEB-INF/views/" + viewName + ".jsp");
return view;
}
}
- ํ๋ก ํธ ์ปจํธ๋กค๋ฌ์์ model์ ๋ง๋ค๊ณ ๊ฐ Controller์ paramMap๊ณผ model์ ๋๊ฒจ ์ฒ๋ฆฌ๋ฅผ ํ๊ณ , viewName์ ๋ฐํ๋ฐ๋๋ค.
- modelView์์ model์ ๊บผ๋ผ ํ์๊ฐ ์๋ค.
ํ์ง๋ง, ์ง๊ธ ControllerV4 ์ธํฐํ์ด์ค๋ก ๋ฐ์ ์ ์๋ ์ปจํธ๋กค๋ฌ๋ฅผ ์ ํํ๊ณ ์๋ค.
์ ์ฐํ Controller - ์ด๋ํฐ ํจํด
์ง๊ธ๊น์ง์ ํ๋ก ํธ ์ปจํธ๋กค๋ฌ๋ ํ๊ฐ์ง ์ธํฐํ์ด์ค๋ง ์ฌ์ฉ์ด ๊ฐ๋ฅํ์๋ค.
์ด๋ ํ ์ปจํธ๋กค๋ฌ๋ ํธํ์ด ๊ฐ๋ฅํ๋๋ก ์ด๋ํฐ ํจํด์ ์ฌ์ฉํ๋ค.
- ํธ๋ค๋ฌ ์ด๋ํฐ : ์ค๊ฐ์ ์ด๋ํฐ ์ญํ ์ ํ๋ ์ด๋ํฐ๊ฐ ์ถ๊ฐ๋์๋ค. ์ด ๋๋ถ์ ๋ค์ํ ์ข ๋ฅ์ ์ปจํธ๋กค๋ฌ๋ฅผ ํธ์ถํ ์ ์๋ค.
- ๊ธฐ์กด์๋ ํ๋ก ํธ ์ปจํธ๋กค๋ฌ๊ฐ ๋ฐ๋ก ์ปจํธ๋กค๋ฌ๋ฅผ ํธ์ถํ์์ง๋ง, ์ด์ ๋ ์ด๋ํฐ๋ฅผ ํตํด์ ํธ์ถํ๋ค.
- ํธ๋ค๋ฌ : ์ปจํธ๋กค๋ฌ์ ์ข ๋ ๋์ ๋ฒ์. ์ด๋ํฐ๊ฐ ์๊ธฐ ๋๋ฌธ์ ์ปจํธ๋กค๋ฌ ๊ฐ๋ ๋ฟ๋ง ์๋๋ผ ํด๋นํ๋ ์ด๋ํฐ๋ง ์์ผ๋ฉด ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํ๋ค.
MyHandlerAdapter
public interface MyHandlerAdapter {
boolean supports(Object handler);
ModelView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException;
}
supports(Object handler)
: ์ด๋ํฐ๊ฐ ํด๋น ์ปจํธ๋กค๋ฌ๋ฅผ ์ฒ๋ฆฌํ ์ ์๋์ง ๋ฐํhandle(...)
: ์ด๋ํฐ๋ ์ค์ ์ปจํธ๋กค๋ฌ๋ฅผ ํธ์ถํ๊ณ ๊ฒฐ๊ณผ๋ก ModelView๋ฅผ ๋ฐํํ๋ค.- ๋ง์ฝ ์ปจํธ๋กค๋ฌ๊ฐ ModelView๋ฅผ ๋ฐํํ์ง ๋ชปํ๋ฉด, ์ด๋ํฐ๊ฐ ์ง์ ์์ฑํ๋ค.
- ํ๋ก ํธ ์ปจํธ๋กค๋ฌ๊ฐ ์๋ ์ด๋ํฐ๊ฐ ์ค์ ์ปจํธ๋กค๋ฌ๋ฅผ ํธ์ถํ๋ค.
ControllerV3HandlerAdapter
public class ControllerV3HandlerAdapter implements MyHandlerAdapter {
@Override
public boolean supports(Object handler) {
return (handler instanceof ControllerV3);
}
@Override
public ModelView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
ControllerV3 controller = (ControllerV3) handler;
Map<String, String> paramMap = createParamMap(request);
ModelView mv = controller.process(paramMap);
return mv;
}
private Map<String, String> createParamMap(HttpServletRequest request) {
Map<String, String> paramMap = new HashMap<>();
request.getParameterNames().asIterator()
.forEachRemaining(paramName -> paramMap.put(paramName,
request.getParameter(paramName)));
return paramMap;
}
}
- supports()๋ก ControllerV3 ํ์ ์ธ์ง ํ์ธํ๊ณ ๋ง๋ค๋ฉด ํธ์ถํ๋ค.
####
@WebServlet(name = "frontControllerServletV5", urlPatterns = "/front-controller/v5/*")
public class FrontControllerServletV5 extends HttpServlet {
private final Map<String, Object> handlerMappingMap = new HashMap<>();
private final List<MyHandlerAdapter> handlerAdapters = new ArrayList<>();
public FrontControllerServletV5() {
initHandlerMappingMap();
initHandlerAdapters();
}
private void initHandlerMappingMap() {
handlerMappingMap.put("/front-controller/v5/v3/members/new-form",
new MemberFormControllerV3());
handlerMappingMap.put("/front-controller/v5/v3/members/save",
new MemberSaveControllerV3());
handlerMappingMap.put("/front-controller/v5/v3/members",
new MemberListControllerV3());
}
private void initHandlerAdapters() {
handlerAdapters.add(new ControllerV3HandlerAdapter());
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// ์์ฒญ ์ ๋ณด๋ก ํธ๋ค๋ฌ๋ฅผ ๊ฐ์ ธ์จ๋ค.
Object handler = getHandler(req);
if (handler == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
// ์ด๋ํฐ๋ฅผ ์ฐพ๋๋ค.
MyHandlerAdapter adapter = getHandlerAdapter(handler);
ModelView mv = adapter.handle(req, resp, handler);
String viewName = mv.getViewName(); // ๋
ผ๋ฆฌ ์ด๋ฆ ex) new-form
MyView view = viewResolver(viewName);
view.render(mv.getModel(), req, resp);
}
private MyHandlerAdapter getHandlerAdapter(Object handler) {
for (MyHandlerAdapter adapter : handlerAdapters) {
if (adapter.supports(handler)) {
return adapter;
}
}
throw new IllegalArgumentException("handler adapter๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. handler " + handler);
}
private Object getHandler(HttpServletRequest req) {
String requestURI = req.getRequestURI();
Object handler = handlerMappingMap.get(requestURI);
return handler;
}
private Map<String, String> createParamMap(HttpServletRequest req) {
Map<String, String> paramMap = new HashMap<>();
req.getParameterNames().asIterator()
.forEachRemaining(paramName -> paramMap.put(paramName, req.getParameter(paramName)));
return paramMap;
}
private MyView viewResolver(String viewName) {
MyView view = new MyView("/WEB-INF/views/" + viewName + ".jsp");
return view;
}
}
- ์์ฑ์ : ํธ๋ค๋ฌ ๋งคํ๊ณผ ์ด๋ํฐ๋ฅผ ์ด๊ธฐํํ๋ค.
- ๋งคํ ์ ๋ณด์ธ handlerMappingMap ์ด Object Map์ผ๋ก ์๋ฌด ํ์ ์ด๋ ๋ฐ์ ์ ์๋ค.
- ํธ๋ค๋ฌ ๋งคํ
- ํธ๋ค๋ฌ๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ ์ด๋ํฐ ์กฐํ
- ์ด๋ํฐ ํธ์ถ
ControllerV4HandlerAdapter ์์
public class ControllerV4HandlerAdapter implements MyHandlerAdapter {
@Override
public boolean supports(Object handler) {
return (handler instanceof ControllerV4);
}
public ModelView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
ControllerV4 controller = (ControllerV4) handler;
Map<String, String> paramMap = createParamMap(request);
HashMap<String, Object> model = new HashMap<>();
// viewName๋ง ๋ฐํํ ๊ฒฝ์ฐ ModelView ๊ฐ์ฒด๋ก ๋ง๋ค์ด์ฃผ๋ ์ญํ ๋ ํ๋ค.
String viewName = controller.process(paramMap, model);
ModelView mv = new ModelView(viewName);
mv.setModel(model);
return mv;
}
private Map<String, String> createParamMap(HttpServletRequest request) {
Map<String, String> paramMap = new HashMap<>();
request.getParameterNames().asIterator()
.forEachRemaining(paramName -> paramMap.put(paramName,
request.getParameter(paramName)));
return paramMap;
}
}
- ์ด๋ํฐ๊ฐ ํธ์ถํ๋ ControllerV4๋ viewName๋ง ๋ฐํํ๋๋ฐ, ์ด๋ ์ด๋ํฐ์์ ์ด๋ฅผ ModelView ๊ฐ์ฒด๋ก ๋ง๋ค์ด ๋ฐํํ๋ค.
ํ๋ก ํธ ์ปจํธ๋กค๋ฌ ์ ์ฅ์์๋ ํธ๋ค๋ฌ ์ด๋ํฐ์๋ง ์์กดํ๊ณ ์๋ค.
์ด MVC ํ๋ ์ ์ํฌ๋ ์ญํ ๊ณผ ๊ตฌํ์ด ๋ถ๋ฆฌ๋์ด ์๋ค.
๋ชจ๋ ๊ฒ์ ์ธํฐํ์ด์ค๋ก ๋ง๋ค๊ณ ๊ตฌํํ๊ณ ์ถ์ ๋ถ๋ถ๋ง ์ฃผ์
ํ๋ฉด ์๋ฒฝ! (์คํ๋ง MVC๋ ๋ทฐ์ ๋ทฐ๋ฆฌ์กธ๋ฒ ๋ค ์ธํฐํ์ด์ค๋ก ๊ตฌํ๋์ด์๋ค.)
์ด๋ค ํธ๋ค๋ฌ๋ฅผ ์ถ๊ฐํ๊ณ ์ถ์ด๋ ์ฐ๋ฆฌ๋ ํธ๋ค๋ฌ์ด๋ํฐ๋ง ๊ตฌํํด์ฃผ๋ฉด ๋๋ค!
ex) @RequestMapping()
RequestMappingHandlerAdapter : ์ ์ด๋ ธํ ์ด์ ์ด ๋ถ์ ํธ๋ค๋ฌ๋ฅผ ์ฒ๋ฆฌํด์ฃผ๋ ์ด๋ํฐ