# Adapter ํŒจํ„ด
Study Repository

Adapter ํŒจํ„ด

by rlaehddnd0422

"์–ด๋Œ‘ํ„ฐ ํŒจํ„ด"์„ ์‚ฌ์šฉํ•˜๋ฉด ControllerV1 ~ ControllerV4๊นŒ์ง€, ์—ฌ๋Ÿฌ ๋ฒ„์ „์˜ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๊ฐˆ์•„๋ผ์›Œ์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์–ด๋Œ‘ํ„ฐ ํŒจํ„ด์„ ์‚ฌ์šฉํ•ด์„œ Front-Controller๊ฐ€ ๋‹ค์–‘ํ•œ ๋ฐฉ์‹์˜ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ฆผ ๊ตฌ์กฐ๋กœ ํ™•์ธํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

ํ•ธ๋“ค๋Ÿฌ : ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋„“์€ ๋ฒ”์œ„์˜ ์ด๋ฆ„์œผ๋กœ, ๊ทธ๋ƒฅ ์ปจํŠธ๋กค๋Ÿฌ๋กœ ์ดํ•ดํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค.

ํ•ธ๋“ค๋Ÿฌ-์–ด๋Œ‘ํ„ฐ : ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)์˜ ์–ด๋Œ‘ํ„ฐ๋กœ ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜์˜ ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์คŒ. ์ž์„ธํ•œ ์„ค๋ช…์€ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

0. Client์—์„œ HTTP์š”์ฒญ์„ ๋ณด๋ƒ…๋‹ˆ๋‹ค.

 

1. ์š”์ฒญ URL Pattern๊ณผ ๋งคํ•‘๋œ FrontController์—์„œ ํ•ธ๋“ค๋Ÿฌ-๋งคํ•‘ ์ •๋ณด๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.

 

2. ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์–ด๋Œ‘ํ„ฐ๊ฐ€ ์žˆ๋Š”์ง€ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.

 

3. ์กฐํšŒํ•œ ์–ด๋Œ‘ํ„ฐ์—์„œ handle(handler) ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๋ฅผ ํ˜ธ์ถœํ•ด ์ปจํŠธ๋กค๋Ÿฌ ๋กœ์ง ์‹คํ–‰ ํ›„ ModelView๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.

 

4. Front-Controller์—์„œ ๋ฆฌํ„ด๋œ ModelView์˜ viewName์„ ํ†ตํ•ด viewResolverํ•ด์„œ viewPath๋ฅผ ์–ป์–ด๋ƒ…๋‹ˆ๋‹ค.

 

5. viewPath๋ฅผ ํ†ตํ•ด MyView์—์„œ JSP๋กœ forward ํ•ด์ค๋‹ˆ๋‹ค.

 

์ˆœ์„œ๊ณผ์ •์„ ์ฝ์–ด๋ด๋„ ํ•œ ๋ฒˆ์— ์™€๋‹ฟ์ง€ ์•Š์•„ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์šฐ์„  FrontController๊ฐ€ ModelView๋ฅผ ๋ฆฌํ„ด๋ฐ›๊ธฐ ์ „๊ณผ ํ›„๋กœ ๋‚˜๋ˆ ์„œ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์šฐ์„  FrontController ์ „์ฒด ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

package hello.servlet.web.frontcontroller.v5;

import hello.servlet.web.frontcontroller.ModelView;
import hello.servlet.web.frontcontroller.MyView;
import hello.servlet.web.frontcontroller.v3.controller.MemberFormControllerV3;
import hello.servlet.web.frontcontroller.v3.controller.MemberListControllerV3;
import hello.servlet.web.frontcontroller.v3.controller.MemberSaveControllerV3;
import hello.servlet.web.frontcontroller.v4.controller.MemberFormControllerV4;
import hello.servlet.web.frontcontroller.v4.controller.MemberListControllerV4;
import hello.servlet.web.frontcontroller.v4.controller.MemberSaveControllerV4;
import hello.servlet.web.frontcontroller.v5.adapter.ControllerV3HandlerAdapter;
import hello.servlet.web.frontcontroller.v5.adapter.ControllerV4HandlerAdapter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@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<>();


    FrontControllerServletV5()
    {
        initHandlerMappingMap();
        initHandlerAdapters();
    }

    private void initHandlerAdapters()
    {
        handlerAdapters.add(new ControllerV3HandlerAdapter());
        handlerAdapters.add(new ControllerV4HandlerAdapter());
    }

    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());

        handlerMappingMap.put("/front-controller/v5/v4/members/new-form",new MemberFormControllerV4());
        handlerMappingMap.put("/front-controller/v5/v4/members/save",new MemberSaveControllerV4());
        handlerMappingMap.put("/front-controller/v5/v4/members",new MemberListControllerV4());

    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Object handler = getHandler(request);
        if(handler==null)
        {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        System.out.println("handler = " + handler);
        MyHandlerAdapter adapter = getHandlerAdapter(handler);
        ModelView mv = adapter.handle(request, response, handler);

        String viewPath = viewResolver(mv.getViewName());
        System.out.println("viewPath = " + viewPath);
        MyView view = new MyView(viewPath);
        view.render(mv.getModel(),request,response);
    }

    private Object getHandler(HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        Object handler = handlerMappingMap.get(requestURI);
        return handler;
    }

    private MyHandlerAdapter getHandlerAdapter(Object handler)
    {
        for (MyHandlerAdapter adapter : handlerAdapters) {
            if(adapter.supports(handler))
            {
                return adapter;
            }
        }
        throw new IllegalArgumentException(
        "handler adapter๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค." + " handler = " + handler);
    }


    private String viewResolver(String viewName) {
        return "/WEB-INF/views/" + viewName + ".jsp";
    }

}

 

ModelView ๋ฆฌํ„ด ๋ฐ›๊ธฐ ์ „์˜ Front-Controller Logic

1. ์š”์ฒญ URI - ์ปจํŠธ๋กค๋Ÿฌ ๋งคํ•‘

private final Map<String, Object> handlerMappingMap = new HashMap<>();

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());

    handlerMappingMap.put("/front-controller/v5/v4/members/new-form",new MemberFormControllerV4());
    handlerMappingMap.put("/front-controller/v5/v4/members/save",new MemberSaveControllerV4());
    handlerMappingMap.put("/front-controller/v5/v4/members",new MemberListControllerV4());

}

HashMap์„ ์ด์šฉํ•ด URI-Handler(์ปจํŠธ๋กค๋Ÿฌ) ๋งคํ•‘์„ ํ†ตํ•ด config

 

2. Handler-Adapter ์ถ”๊ฐ€

private final List<MyHandlerAdapter> handlerAdapters = new ArrayList<>();

FrontControllerServletV5()
{
    initHandlerMappingMap(); // URI - Handler
    initHandlerAdapters(); // Handler - Adapter
}

private void initHandlerAdapters()
{
    handlerAdapters.add(new ControllerV3HandlerAdapter());
    handlerAdapters.add(new ControllerV4HandlerAdapter());
}

์—ฌ๊ธฐ์„œ MyHandlerAdapter๋Š” ํ•ธ๋“ค๋Ÿฌ-์–ด๋Œ‘ํ„ฐ์˜ ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค.

๋‹คํ˜•์„ฑ์„ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

public interface MyHandlerAdapter {
    boolean supports(Object handler);

    ModelView handle(HttpServletRequest request, HttpServletResponse response,
                     Object handler) throws ServletException, IOException;
}

์–ด๋Œ‘ํ„ฐ์—์„œ๋Š” ๋‘ ๊ฐ€์ง€ ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. 

  1. boolean supports(Object handler) : ์–ด๋Œ‘ํ„ฐ๊ฐ€ ์ด ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š”์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€
  2. ModelView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException : ์–ด๋Œ‘ํ„ฐ๊ฐ€ ์‹ค์ œ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ModelView๋ฅผ ๋ฐ˜ํ™˜. ์ด์ „์—๋Š” ํ”„๋ก ํŠธ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์‹ค์ œ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ํ˜ธ์ถœํ–ˆ์ง€๋งŒ ์ด์ œ๋Š” ์ด ์–ด๋Œ‘ํ„ฐ๋ฅผ ํ†ตํ•ด์„œ ์‹ค์ œ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

์šฐ์„  ์‹ค์ œ ์–ด๋Œ‘ํ„ฐ๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

ControllerV3 ์–ด๋Œ‘ํ„ฐ ์ž…๋‹ˆ๋‹ค.

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์˜ ์ธ์Šคํ„ด์Šค์ธ์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€ ๋ฆฌํ„ด
  • handle : ํ•ธ๋“ค๋Ÿฌ๋ฅผ ControllerV3๋กœ Object->ControllerV3๋กœ ํƒ€์ž…๋ณ€ํ™˜ โ–ถ๏ธŽ request๋ฅผ ํ†ตํ•ด ์ „๋‹ฌ๋œ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ paramMap์„ ์–ป์Œ โ–ถ๏ธŽ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ํ˜ธ์ถœํ•ด process(ํŒŒ๋ผ๋ฏธํ„ฐ ํ• ๋‹น, JSP ๋™์  ๋ฆฌ์†Œ์Šค ๋ชจ๋ธ์— put ๋“ฑ ) ํ•œ ํ›„ ์ƒ์„ฑ๋œ ModelView๋ฅผ ๋ฆฌํ„ด

์ฆ‰ ์–ด๋Œ‘ํ„ฐ์—์„œ ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ  ModelView๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.

 

๋‹ค์Œ์€ ControllerV4 ์–ด๋Œ‘ํ„ฐ์ž…๋‹ˆ๋‹ค.

package hello.servlet.web.frontcontroller.v5.adapter;

import hello.servlet.web.frontcontroller.ModelView;
import hello.servlet.web.frontcontroller.MyView;
import hello.servlet.web.frontcontroller.v3.ControllerV3;
import hello.servlet.web.frontcontroller.v4.ControllerV4;
import hello.servlet.web.frontcontroller.v5.MyHandlerAdapter;
import org.springframework.ui.Model;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ControllerV4HandlerAdapter implements MyHandlerAdapter {
    @Override
    public boolean supports(Object handler) {
        return (handler instanceof ControllerV4);
    }

    @Override
    public ModelView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
        ControllerV4 controller = (ControllerV4) handler;

        Map<String,String> paramMap = createParamMap(request);
        Map<String,Object> model = new HashMap<>();

        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;
    }

    private String viewResolver(String viewName) {
        return "/WEB-INF/views/" + viewName + ".jsp";
    }

}
  • supports : ์ด ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๊ฐ€ ControllerV3์˜ ์ธ์Šคํ„ด์Šค์ธ์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€ ๋ฆฌํ„ด
  • handle : ControllerV4์—์„œ๋Š” model๊ณผ paramMap์„ process์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ์ฃผ๊ณ  viewName์„ ๋ฆฌํ„ด๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด ๊ตฌํ˜„ ํ–ˆ์Šต๋‹ˆ๋‹ค. viewName์„ ์ฃผ์ž…๋ฐ›์€ ModelView์„ ๋ฆฌํ„ดํ•˜๊ณ  process๋ฅผ ํ†ตํ•ด ์—…๋ฐ์ดํŠธ๋œ model์„ setํ•ด์ค€ ModelView๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.

3. ์š”์ฒญ URI์— ๋งž๋Š” ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)์™€ ์–ด๋Œ‘ํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    Object handler = getHandler(request);
    if(handler==null)
    {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    MyHandlerAdapter adapter = getHandlerAdapter(handler);
    ...
}

private Object getHandler(HttpServletRequest request) {
    String requestURI = request.getRequestURI();
    Object handler = handlerMappingMap.get(requestURI);
    return handler;
}

private MyHandlerAdapter getHandlerAdapter(Object handler)
{
    for (MyHandlerAdapter adapter : handlerAdapters) {
        if(adapter.supports(handler))
        {
            return adapter;
        }
    }
    throw new IllegalArgumentException(
    "handler adapter๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค." + " handler = " + handler);
}
  • getHandler(request) : ์š”์ฒญ URI๋ฅผ ํ†ตํ•ด ํ•ธ๋“ค๋Ÿฌ๋งต์— ๋งคํ•‘ํ•˜์—ฌ ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
  • getHandlerAdapter(getHandler๋ฅผ ํ†ตํ•ด ์–ป์€ handler) : List๋ฅผ iteratorํ•˜๊ฒŒ ์‚ดํŽด๋ณด๊ณ  supports ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•ด ํ•ด๋‹น ํ•ธ๋“ค๋Ÿฌ์™€ ํ˜ธํ™˜๋˜๋Š” ์–ด๋Œ‘ํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. 

ModelView๋ฅผ ๋ฆฌํ„ด๋ฐ›์€ ํ›„์˜ Front-Controller Logic

package hello.servlet.web.frontcontroller.v5;

import hello.servlet.web.frontcontroller.ModelView;
import hello.servlet.web.frontcontroller.MyView;
import hello.servlet.web.frontcontroller.v3.controller.MemberFormControllerV3;
import hello.servlet.web.frontcontroller.v3.controller.MemberListControllerV3;
import hello.servlet.web.frontcontroller.v3.controller.MemberSaveControllerV3;
import hello.servlet.web.frontcontroller.v4.controller.MemberFormControllerV4;
import hello.servlet.web.frontcontroller.v4.controller.MemberListControllerV4;
import hello.servlet.web.frontcontroller.v4.controller.MemberSaveControllerV4;
import hello.servlet.web.frontcontroller.v5.adapter.ControllerV3HandlerAdapter;
import hello.servlet.web.frontcontroller.v5.adapter.ControllerV4HandlerAdapter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@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<>();


    FrontControllerServletV5()
    {
        initHandlerMappingMap();
        initHandlerAdapters();
    }

    private void initHandlerAdapters()
    {
        handlerAdapters.add(new ControllerV3HandlerAdapter());
        handlerAdapters.add(new ControllerV4HandlerAdapter());
    }

    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());

        handlerMappingMap.put("/front-controller/v5/v4/members/new-form",new MemberFormControllerV4());
        handlerMappingMap.put("/front-controller/v5/v4/members/save",new MemberSaveControllerV4());
        handlerMappingMap.put("/front-controller/v5/v4/members",new MemberListControllerV4());

    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Object handler = getHandler(request);
        if(handler==null)
        {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        MyHandlerAdapter adapter = getHandlerAdapter(handler);
        ModelView mv = adapter.handle(request, response, handler);

        String viewPath = viewResolver(mv.getViewName());
        MyView view = new MyView(viewPath);
        view.render(mv.getModel(),request,response);
    }

    private Object getHandler(HttpServletRequest request) {
        String requestURI = request.getRequestURI();
        Object handler = handlerMappingMap.get(requestURI);
        return handler;
    }

    private MyHandlerAdapter getHandlerAdapter(Object handler)
    {
        for (MyHandlerAdapter adapter : handlerAdapters) {
            if(adapter.supports(handler))
            {
                return adapter;
            }
        }
        throw new IllegalArgumentException(
        "handler adapter๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค." + " handler = " + handler);
    }


    private String viewResolver(String viewName) {
        return "/WEB-INF/views/" + viewName + ".jsp";
    }

}

adapter์˜ handle์„ ํ†ตํ•ด ๋ฆฌํ„ด๋œ ModelView์—์„œ viewName(๋ทฐ ๋…ผ๋ฆฌ ์ด๋ฆ„)ํ•„๋“œ๋ฅผ ViewResolver ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ์‹ค์ œ viewPath๋ฅผ ๊ฐ€์ง€๊ณ  MyView ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด JSP๋กœ forwardํ•ฉ๋‹ˆ๋‹ค.

 

<์ •๋ฆฌ>

1. ์–ด๋Œ‘ํ„ฐ๋ฅผ ๋„์ž…ํ•ด์„œ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ํ™•์žฅ์„ฑ์žˆ๊ฒŒ ์„ค๊ณ„ ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

2. ๋‹คํ˜•์„ฑ์„ ์ด์šฉํ•œ ์–ด๋Œ‘ํ„ฐ ๋•๋ถ„์— ๊ธฐ์กด ๊ตฌ์กฐ๋ฅผ ์œ ์ง€ํ•˜๋ฉด์„œ ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ธฐ๋Šฅ์„ ํ™•์žฅํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

์—ฌ๊ธฐ์— ์–ด๋…ธํ…Œ์ด์…˜์„ ์ง€์›ํ•˜๋Š” ์–ด๋Œ‘ํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ๋ฐœ์ „์‹œํ‚ฌ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. 

์ด์ „ ํฌ์ŠคํŒ…๊ณผ ์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ MVC ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด๋ณด๊ณ  ํ™•์žฅํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ํฌ์ŠคํŒ…์—์„œ๋Š” ์Šคํ”„๋ง ๋ถ€ํŠธ๋ฅผ ์ด์šฉํ•œ MVC ๊ตฌ์กฐ๋ฅผ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

 

<์ฐธ๊ณ ์ž๋ฃŒ>

https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-mvc-1/dashboard

 

์Šคํ”„๋ง MVC 1ํŽธ - ๋ฐฑ์—”๋“œ ์›น ๊ฐœ๋ฐœ ํ•ต์‹ฌ ๊ธฐ์ˆ  - ์ธํ”„๋Ÿฐ | ๊ฐ•์˜

์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•  ๋•Œ ํ•„์š”ํ•œ ๋ชจ๋“  ์›น ๊ธฐ์ˆ ์„ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ดํ•ดํ•˜๊ณ , ์™„์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Šคํ”„๋ง MVC์˜ ํ•ต์‹ฌ ์›๋ฆฌ์™€ ๊ตฌ์กฐ๋ฅผ ์ดํ•ดํ•˜๊ณ , ๋” ๊นŠ์ด์žˆ๋Š” ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž๋กœ ์„ฑ์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค., -

www.inflearn.com

https://chinggin.tistory.com/586

 

ํ•ธ๋“ค๋Ÿฌ ๋งคํ•‘๊ณผ ํ•ธ๋“ค๋Ÿฌ ์–ด๋Œ‘ํ„ฐ

๊ฐœ๋ฐœ ๊ณต๋ถ€๋ฅผ ํ•  ๋•Œ ๊ณผ๊ฑฐ์— ์–ด๋–ป๊ฒŒ ๊ฐœ๋ฐœํ–ˆ๋Š”์ง€๋ฅผ ์•„๋Š” ๊ฒƒ์€ ์ƒ๋‹นํ•œ ๋ฉ”๋ฆฌํŠธ๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ๊ณผ๊ฑฐ์—์„œ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ๋ฅผ ๊ฐœ์„ ํ•œ ์ฝ”๋“œ๊ฐ€ ํ˜„์žฌ ๋ฐ˜์˜๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์–ด๋– ํ•œ ๋ฌธ์ œ๋ฅผ ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ–ˆ

chinggin.tistory.com

 

๋ธ”๋กœ๊ทธ์˜ ์ •๋ณด

Study Repository

rlaehddnd0422

ํ™œ๋™ํ•˜๊ธฐ