버전 01
개발자가 직접만든 Controller 인터페이스 사용
output이 ActionForward 이었는데
VR 가 등장하면서 String으로 변경됨
String 유무로 VR 있는지 알수있다
어디로(경로),어떻게(방식 : 리다이렉트, 포워드)
// Action
public interface Controller{
// ActionForward → String
String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
}
// ActionForward 가 필요없어짐!
public class ViewResolver {
public String prefix;
public String suffix;
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public String getView(String view) {
return prefix+view+suffix;
}
}
버전 02
Spring 프레임워크에서 제공하는 Controller를 impl(구현,상속)하여 사용
Controller
import org.springframework.web.servlet.mvc.Controller;
ModelAndView -> 데이터 다음페이지

ModelAndView mav=new ModelAndView();
mav.setViewName("main");//포워트 + main.jsp
mav.addObject("mdatas",mdatas);//==request.setAttribute("mdatas", mdatas);
HttpServletRequest는 서블릿이라 무거운데 ModelAndView (POJO)로 바뀌면서 가벼워짐
기존에는 requerst(not POJO) 객체를 통해 데이터를 전달 -> 무거움
ModelAndView(mav,POJO) 객체를 통해 데이터를 전달-> 가벼음
-> 강제가 되니까 실수가 줄음

버전 03
@Component + implements Conroller -> @Controller
@Component
@Repository @Service @Controller
@Controller 어노테이션 사용하면 좋은 이유
오버라이드가 필요없어짐
메서드의 시그니쳐가 강제가 안됨
마음대로 이름을 지을수있음
메서드 시그니쳐의 강제성이 없음 -> 하나의 Controller 에서 여러 기능(서로 관련된)을 작성할 수 있음
필요한것끼리는 같이 관리하면좋음
하나의 컨트롤러에 관련된 기능을 다룰수 있게되었다
코드의 응집도를 높임
->자유도가 높음

'Spring' 카테고리의 다른 글
| ViewResolver 모음 (0) | 2024.03.21 |
|---|---|
| HandlerMapping 모음 (0) | 2024.03.20 |
| SpringMVC 구조 개념 (0) | 2024.03.18 |
| DispatcherServlet 모음 (0) | 2024.03.17 |
| 트랜잭션 (1) | 2024.03.16 |