Spring+hibernate+springmvc 整合(六)

3、spring mvc 配置

A )web.xml 文件

<!--   spring mvc -->

    <servlet>

        <servlet-name>dmt</servlet-name>

        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>/WEB-INF/*-servlet.xml</param-value>

        </init-param>

        <load-on-startup>0</load-on-startup>

    </servlet>

    <servlet-mapping>

        <servlet-name>dmt</servlet-name>

        <url-pattern>*.do</url-pattern> <!--匹配跳转的后缀名-->

                               </servlet-mapping>

B)Dmt-serverlet.xml 文件

 <context:component-scan base-package="com.hb"  use-default-filters="false"> 

         <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>

    </context:component-scan> 

 

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>

 

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"  lazy-init="false"/>

 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />

        <property name="prefix" value="/WEB-INF/jsp/" />

        <property name="suffix" value=".jsp" />

    </bean>

    <!-- 配置  xml 方式下的url mapping 和 parameterMethod

    在 整合进注解 mvc 后 必须加上 SimpleControllerHandlerAdapter 的配置

     -->

   <bean id="urlMapping"

   class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">

   <property name="order" value="1"></property>

   </bean>

   <bean

   class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

   <bean id="methodNameResolver"

   class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">

   <property name="paramName" value="method" />

   <property name="defaultMethodName" value="index" />

   </bean>


你可能感兴趣的:(spring,bean,Hibernate,mvc,servlet,Class)