spring-integrated springMVC

Configuration

  • Before web.xmlconfiguring the front controller

  • If you do not configure contextConfigLocation, it will go to / WEB-INF / to find the "name" of the servlet -servlet.xml

<!-- 前端控制器 -->
<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <!-- 如果不配置核心配置文件,就会默认去找/WEB-INF/springMvc-servlet.xml -->
        <!-- 修改配置文件所在路径 -->
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:springmvc.xml</param-value>
    </init-param>
        <!-- 配置tomcat启动就加载优先级,如果不配,则是在第一次访问的时间进行加载 -->
        <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.action</url-pattern>
</servlet-mapping>
  • Intercept expression
expression Explanation
*.action Intercept URLs that have ended .action
/ Cut all, excluding the end of the .jsp file
/* Intercept all end of files including .jsp

SpringMvcs core configuration file

  • If the mapper and adapter are not configured, by default, every request goes back to DispatcherServlet.propertiesthis file to find the corresponding processor and adapter to execute, which will greatly reduce the access speed of the system,
    so we set the corresponding mapper and adapter, so that it does not Will find the default configuration, which can improve the access efficiency of the system
    • Note : But we will not configure it this way, because this configuration is too fixed, if the springMVC version is updated, you need to update the configuration file, you can configure a label to solve this problem

Annotation-driven

  • Its role is to find the latest version of the processor and adapter,

  • It has nothing to do with annotations and drivers. With this, there is no need to configure the following mapper and adapter.

  <mvc:annotation-driven />
  • Annotation mapper

    • Map the method of @ResquestMapping in the class, match the method of the ResquestMapping tag according to the url defined by ResquestMapping, and
      return the HandlerMethod object to the front-end controller after the match is successful. The HandlerMethod object encapsulates the method corresponding to the url Method.
 <!--新版本注解映射器 -->
     <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
 <!--老版本注解映射器 -->
     <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"  />
  • Annotation adapter: Annotation processor adapter to adapt the method marked @ResquestMapping.
<!--新版本注解适配器 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<!--老版本注解适配器 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"  />

Try parser

  • Configuration view resolution:

    • Purely for development convenience
      InternalResourceViewResolver: support JSP view resolution
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- viewClass:JstlView表示JSP模板页面需要使用JSTL标签库,所以classpath中必须包含jstl的相关jar 包。此属性可以不设置,默认为JstlView。-->
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <!-- prefix:查找视图页面的前缀-->
    <property name="prefix" value="/" />
    <!-- suffix :查找视图页面的后缀-->
    <property name="suffix" value=".jsp" />
</bean>
发布了20 篇原创文章 · 获赞 0 · 访问量 930

Guess you like

Origin blog.csdn.net/vistaed/article/details/105558616