5. Summary of Starter Programs for SpringMVC

Keywords: Programming JSP Spring xml JSON

Summary of Getting Started Program Configuration

Front End Controller Configuration:

  • First: *.action, access ends with.action and is resolved by Dispatcher Servlet
  • Second: /, all addresses accessed are resolved by Dispatcher Servlets, which configure Dispatcher Servlets not to resolve static files to implement RESTful-style URLs

Processor Mapper:

  • Non-annotated processor mapper
  • Annotated processor mapper

Map the methods identified as @RequestMapping in the tag @Controller class.Define the url of the map inside @RequestMapping.Mapper using annotations does not configure the mapping relationship between url and Handler in xml.

Processor adapter:

  • Non-annotated processor adapter
  • Annotated processor adapter

Annotation Processor Adapter and Annotation Processor Mapper are used in pairs.

<mvc:annotation-driven></mvc:annotation-driven> 

Instead of the following configuration:

<!--Annotation Mapper -->  
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>  
<!--Annotation adapter -->  
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>  

Non-annotated complete configuration file

src/main/resources/springmvc.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    <!-- To configure Handler -->
    <bean name="/queryItems.action" class="com.iot.ssm.controller.ItemsController"/>
    <!-- The processor mapper will bean Of name As url Find, need to configure Handler When specified beanname(Namely url)-->
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
    <!-- Processor adapters All processor adapters are implemented HandlerAdapter Interface-->
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
    <!-- View Parser Resolution jsp,Default Use jstl,classpath Next must be jstl Package for-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>
</beans>

Annotated Full Profile

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <!-- For annotated Handler´╝îComponent scanning can be used in actual development with a single configuration-->
    <!-- <bean  class="com.iot.ssm.controller.ItemsController3"/> -->
    <!-- Scannable controller,service,...Scan here controller´╝îAppoint controller Package for-->
    <context:component-scan base-package="com.iot.ssm.controller"></context:component-scan>
    <!-- Annotation Mapper -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
    <!-- Annotated adapter -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
    <!-- Use mvc:annotation-driven Instead of the above two annotation mappers and annotation adapter configurations, mvc:annotation-driven Load many parameter binding methods by default, such as json Conversion parser loaded by default if used mvc:annotation-driven Do not configure the above RequestMappingHandlerMapping and RequestMappingHandlerAdapter Use in actual development mvc:annotation-driven
     -->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!-- View Parser Resolution jsp,Default Use jstl,classpath Next must be jstl Package for-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- To configure jsp Path prefix -->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!-- To configure jsp Suffix of path -->
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

Posted by waseembari1985 on Thu, 07 Nov 2019 08:35:58 -0800