7. MVC Patten N Spring

  • View
    12

  • Download
    1

Embed Size (px)

DESCRIPTION

Mvc tutorial

Text of 7. MVC Patten N Spring

MVC Spring

MVC

1

MVC

2 - MVC

MVC

Controller( Action) (Java Script JSP(View) ) Layer Layer Interface Layer Layer View

MVC

Model ?

MVC

Model

=

Domain Model

MVC

Domain Model +

Model

=

Business Obj +

DAO

MVC

1B R O W S E R

1. Request

JSP2. Response

MVC

21. Request

B R O W S E R

(Controller) Servlet2. Response

3. Request

(View) JSP4. Response

Spring Framework - MVC

Spring Framework - MVC

Spring Framework - MVC

2

Spring MVC

HandlerMapping

2

3 1DispatcherServlet ModelAndView Controller

4 5 6View

ViewResolver

Spring MVC

Spring MVC - Controller

1

HelloWorldController

Spring MVC

BeanNameUrlHandlerMapping

2/index.html

3 1DispatcherServlet ModelAndView index MyUrlFilenameViewController

4

5 6

InternalResourceViewResolver

/WEB-INF/jsp/index.jsp

Spring MVC - Controller

Spring MVC - Controller

UrlFilenameViewController

=No Model

Spring MVC - Controller

MultiActionController

=DispatchAction of StrutsAction of Webwork

Spring MVC - Controller

List.do

B R O W S E R

ListAction InsertAction UpdateAction ViewAction DeleteAction

Insert.do Update.do View.do Delete.do

URL : Action

=

1:1

Spring MVC - Controller

URL Action(Controller) . Action(Controller) Action URL . Action(Controller) . .

Spring MVC - Controller

List.do

B R O W S E R

Insert.do Update.do View.do Delete.do

SampleAction

URL : Action

=

N:1

Spring MVC - Controller

2

MultiHelloWorldController

Spring MVC - Controller

Spring MVC - Controller

SimpleFormController

Spring MVC - BeanNameHandlerMapping

Spring MVC - SimpleUrlHandlerMapping

Spring MVC - SimpleUrlHandlerMapping

loginFormController boardController

Spring MVC - Interceptor

Spring MVC Interceptor loginFormController boardController

Spring MVC - View

JSTLView

HTML

ExcelView Model

Excel

PDFView

PDF

CSVView

CSV

Spring MVC - ViewResolver

InternalResource ViewResolver

JSP

Velocity ViewResolver Model

Velocity

FreeMarker ViewResolver

Freemarker

ResourceBundleViewResolver

ResourceBundle

Spring MVC - ViewResolver ViewResolver Chain org.springframework.web.servlet.view.JstlView

InternalResourceViewResolver Chain

Property Editor

Property Editor ? java.beans.PropertyEditor

Property Editor java.lang.String c:/test.txt en-GB http://www.springframework.org name=foo age=19 rob,jan,rod,jurgen,alef Hello World

Property Editorimport import import import java.io.File; java.net.URL; java.util.Locale; java.util.Properties;

public class PropertyEditorBean { private Class cls; private File file; private URL url; private Locale locale; private Properties properties;

private String[] strings;private byte[] bytes; }

Spring 2.0

Convention over Configuration (CoC)

Spring 2.0

Controller

HelloWorldController => helloworld.do HelloWorldController.hello => helloworld/hello.do

Spring 2.0

Model x.y.User => user java.util.HashMap => hashMap x.y.User[] => userList x.y.User java.util.ArrayList => userList

Spring 2.0

View

http://localhost:8080/helloworld.do => WEB-INF/jsp/helloworld.jsp http://localhost:8080/helloworld/hello.do => WEB-INF/jsp/helloworld/hello.jsp

Spring 2.0

3

MultiHelloWorldController CoC

Spring

Spring

Spring

Spring

!! RequestDispatcher : http://wiki.javajigi.net/pages/viewpage.action?pageId=77 Simplify Your Web App Development Using the Spring MVC Framework : http://www.devx.com/Java/Article/22134/1954?pf=true Property Editor Sample : http://www.java2s.com/Code/Java/Spring/PropertyEditorBean.htm