zoukankan      html  css  js  c++  java
  • Springmvc中的HandlerAdaptor执行流程

    1.0在DispatcherServlet中找到getHandlerAdapter()方法:

    2.0进入getHandlerAdapter()具体的方法实现内:

    3.0获取ModelAndView:

    4.0执行者:

    好了架构已经搭建完了,现在我们来搞代码。。。。。

    1.依赖的节点:

     <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.3</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>4.3.3.RELEASE</version>
            </dependency>
    
            <!--spring web jar 包-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>4.3.3.RELEASE</version>
            </dependency>
    
            <!--springmvc jar 包-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>4.3.3.RELEASE</version>
            </dependency>
    
            <!--spring-ormjar 包-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>4.3.3.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>1.8.7</version>
            </dependency>
    
            <!--servlet api包-->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.taglibs</groupId>
                <artifactId>taglibs-standard-spec</artifactId>
                <version>1.2.1</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.taglibs</groupId>
                <artifactId>taglibs-standard-impl</artifactId>
                <version>1.2.1</version>
            </dependency>
    
        </dependencies>
    
        <build>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                        <include>**/*.properties</include>
                    </includes>
                </resource>
            </resources>
        </build>
    2.web:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             xsi:schemaLocation="
             http://java.sun.com/xml/ns/javaee
             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             version="2.5">
      <display-name>Archetype Created Web Application</display-name>
    
      <!--中央调度器-->
      <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:applicationContextfirst.xml</param-value>
        </init-param>
      </servlet>
      
      <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    </web-app>

    1.访问类:
    public class FirstController implements Controller{
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
            ModelAndView av=new ModelAndView();
            av.setViewName("index");
            return av;
        }
    } 
    2.编写applicationfirst:
    <!--第一种方式实现-->
        <!--处理器-->
        <bean id="firstController" class="cn.happy.controller.FirstController"></bean>
    
        <!--处理器映射器-->
        <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/hello">firstController</prop>
                </props>
            </property>
        </bean>
    
        <!--视图解析器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
    好了今天先搞一种,后面会继续有。。。。
  • 相关阅读:
    解释一下什么是servlet?
    HTTP请求的GET与POST方式的区别
    金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出?
    Java中的异常处理机制的简单原理和应用。
    error和exception有什么区别?
    运行时异常与一般异常有何异同?
    jsp有哪些动作?作用分别是什么?
    jsp有哪些内置对象?作用分别是什么? 分别有什么方法?
    一个纸杯的测试用例
    白盒测试黑盒测试区别
  • 原文地址:https://www.cnblogs.com/cuntouyixiaohuo/p/6710465.html
Copyright © 2011-2022 走看看