1. 程式人生 > >spring mvc 的設計模式

spring mvc 的設計模式

  1. 使用spring,在web.xml中配置一個DispatcherServlet。
   <!--配置 spring 的DispatcherServlet-->
<servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name
>
contextConfigLocation</param-name> <!--給出框架配置檔案所在的路徑--> <param-value>classpath:conf/freemarker-servlet.xml</param-value> </init-param> </servlet> <!--freemarker-servlet在conf/freemarker-servlet.xml檔案中的引數配置如下--> <!-- freemark -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/ftl/" /> <property name="defaultEncoding" value="UTF-8" /> </bean> <bean class
="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" /> <property name="prefix" value="" /> <property name="suffix" value=".ftl" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> <property name="requestContextAttribute" value="request" /> <property name="contentType" value="text/html; charset=utf-8" /> </bean> <!--web.xml中的攔截會直接跳轉到對應的方法, 我們並不關心--> <servlet> <servlet-name>authenticationServlet</servlet-name> <servlet-class> com.suning.ids.client.AuthenticationServlet </servlet-class> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <!--所有連線中包含/auth的url--> <!--都跳轉到com.suning.ids.client.AuthenticationServlet--> <servlet-name>authenticationServlet</servlet-name> <url-pattern>/auth</url-pattern> </servlet-mapping> <!--只關心controller中request的方法-->
    2.