Inside Spring Web MVC 안영회 ahnyounghoe@gmail.com 차례 MVC 개요와오해 Spring Web MVC 개요 Demo 로이해하는 Spring Web MVC 대표적인컨트롤러활용 정리
한국 스프링 사용자 모임 MVC 개요와 오해 한국 스프링 사용자 모임 MVC 개요
MVC 에대한오해 컨트롤러는서블릿이다! 컨트롤러는액션이다! 비즈니스로직은컨트롤러다! 모델은 VO다! 상황에따라다른 MVC 적용
Tier 를고려해보면 Server-side MVC RIA 를채택한다면 MVC in RIA
Spring Web MVC 개요 Spring Web MVC 의처리흐름개요
Spring Web MVC 의 Front Controller 구현 Front Controller(Core J2EE Patterns)
Front Controller(Core J2EE Patterns) Command 와 Controller 활용전략 Front Controller(Core J2EE Patterns) Dispatcher 활용전략
Demo로이해하는 Spring Web MVC Demo 환경 Tomcat 5.5.23 JDK1.6.0.01 Eclipse WTP 1.5.4 Windows Vista 그리고 from the scratch 예제
1) DispatcherServlet t 관문 코디네이터 Inside Spring Web MVC Framework Servlet Dispatcher Servlet ApplicationCont ext 이벤트관련 주요 Mapping /Resolver 로딩 프레임워크기반기능 Do Dispatch
Inside Spring Web MVC How to program web.xml에 <servlet> 및 <servletmapping> 선언 ${servlet-name}-servlet.xml servlet.xml 파일작성
2) Handler Mapping HTTP 요청 -> 처리기 Inside Spring Web MVC dodispatch() > > gethandler() gethandler() code Iterator it = this.handlermappings.iterator(); while (it.hasnext()) { HandlerMapping hm = (HandlerMapping) it.next(); handler = hm.gethandler(request); return handler;
How to program Do nothing! 일단디폴트설정을활용 BeanNameUrlHandlerMapping 3) Controller Spring Web MVC 의요청처리기
How to program 네비게이션만만들어두자. JSP 만호출해주는컨트롤러활용 ParameterizableViewController 4) ModelAndView dvi /6)Vi View View 에데이터모델제공 다양한 View 구현추상화
Inside Spring Web MVC 5) View Resolver 논리적 View 이름 -> 물리적 View 파일
Inside Spring Web MVC dodispatch() > render() > resolveviewname () resolveviewname() code for (Iterator it = this.viewresolvers.iterator(); it.hasnext();) { ViewResolver viewresolver = (ViewResolver) it.next(); View view = viewresolver.resolveviewname(viewname, l i N locale); l if (view!= null) { return view;} } How to program View 유형에따라선택 InternalResourceViewResolver FreeMarkerViewResolver VelocityViewResolver XmlViewResolver
대표적인컨트롤러활용 기본적인요청수행 기본적인정보를보자 할일목록을보는페이지작성 어떻게하나? 1. Controller 코드작성 2. Spring configuration 1. Dependency Injection
AbstractController tc t Form 처리 입력양식을만들어보자 할일을입력하는페이지작성 어떻게하나? 1. Controller 코드작성 2. Spring configuration 1. Dependency Injectio
Inside SimpleFormController ll 1. Form 제출인지판단? No AbstractFormController.isFormSubmission() b i i 2. 새로운 Form 객체생성 1. AbstractFormController.showNewForm() 2. formbackingobject() 3. createcommand() 3. Binder 생성및초기화 1. BaseCommandController.createBinder() 2. initbinder() > 내용없음 Inside SimpleFormController ll 4. 오류가있다면 Model 로반환 reference Data 가있으면 Model 에병합 AbstractFormController.showForm Map model = errors.getmodel(); referencedata(request, t errors.gettarget(), t() errors); return new ModelAndView(viewName, model); 4. Form View 출력
입력화면에서보여줄데이터 선택을위한데이터입력 Form 작성 어떻게하나? referencedata() 템플릿메소드구현 뷰에서모델과동일하게처리 기본형이아닌데이터입력 숫자나문자이외의데이터를화면에서입력하기 어떻게하나? PropertyEditor 코드작성 initbinder() 템플릿메소드에서 binder.registercustomeditor()
Inside SimpleFormController ll 1. Form 제출인지판단? Yes AbstractFormController.isFormSubmission() b i i 2. 세션에서 Form 객체꺼내거나새로운 Form 객체생성 1. AbstractFormController.getCommand() 2. issessionform() True: session.getattribute() False: formbackingobject() Inside SimpleFormController ll 3. Bind 와 validate 1. BaseCommandController.bindAndValidate() d d lid 1. createbinder() 2. 등록된 validator 활용 3. onbindandvalidate() > 내용없음 4. Form 제출처리 SimpleFormController.processFormSubmission() 오류여부 있으면 : showform() 없으면 : onsubmit()
잘못된값세련되게걸러내기 Separation of Concerns 어떻게하나? Validator 구현코드작성 validator 혹은 validators 프로퍼티로등록 Controller 인터페이스구현클래스
정리 Spring Web MVC 의핵심개념 DispatcherServlet Handler Mapping View Resolver Controller Validator Command Model
Et Extra Tips Spring Formatter http://www.springframework.org/files/active/ 0/spring-eclipse-code-conventions.xml Templates for JUnit4, Spring config Throw UnsupportedOperationException! Spring IDE 예고편 Spring Web MVC 실전활용 간결한공통클래스만들기 대규모 Url 을가진사이트를위한 CoC 적용 Freemarker 의활용 Excel 리포팅 6 주후에봅시다.
Resources MVC 개념 http://en.wikipedia.org/wiki/model-view-controller p// p / http://osteele.com/archives/2004/08/web-mvc Spring Web MVC 개요 http://static.springframework.org/spring/docs/2.0.x/reference/mvc.htmlspringframework org/spring/docs/2 html http://java.sun.com/blueprints/corej2eepatterns/patterns/frontcontroller.h tml Demo Expert Spring MVC and Web Flow (Expert) by Seth Ladd, Darren Davison, Steven Devijver, and Colin Yates http://younghoe.info/273 h /273 http://blog.empas.com/ahnyounghoe/read.html?a=12332593 Resources Demo http://blog.empas.com/ahnyounghoe/read.html?a=13620546 p// p / g / http://blog.empas.com/ahnyounghoe/read.html?a=12334324 http://blog.empas.com/ahnyounghoe/read.html?a=15454196 http://blog.empas.com/ahnyounghoe/read.html?a=12398750 html?a=12398750 Extra Tips http://younghoe.info/479 http://younghoe.info/482 http://younghoe.info/497