• spring MVC配置


    从url:http://localhost:8080/graduate/showView.do开始

    进入到web.xml

    wem.xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        
        <!--加载springmvc的核心配置文件-->
        <servlet>
            <servlet-name>springmvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!--采用这种的话则springmvc.xml必须放在web-inf文件下,若是采用initparam配置的话则可以放在其他地方--> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>

    通过<servlet-mapping>拦截*.do,转交给<servlet>-->DispatcherServlet找到sprinmvc-servlet.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
    
    
        <mvc:annotation-driven />
        
        <mvc:default-servlet-handler />
        <context:component-scan base-package="controller" />
    
    
    
    </beans>

    进入到spring.xml,通过<context:component-scan base-package="controller" />扫描controller包,扫描所有带@controller的类,然后通过扫描@requestMapping绑定用户请求,然后执行代码,响应请求

    package controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    @Controller
    
    public class MyController {
        @RequestMapping ( "showView" )
        public ModelAndView showView() {
           ModelAndView modelAndView = new ModelAndView();
           modelAndView.addObject( "msg" , " hello world " );
           modelAndView.setViewName( "MyJsp.jsp" );
          
           return modelAndView;
        }
    
    }

    以上就是springMVC的简单配置,以及。。。一个大概的流程???算吗???emmm。。。不知道算不算。。。

    不知道我觉得这里讲的https://www.bilibili.com/video/BV1r4411k721?p=4应该还好理解

  • 相关阅读:
    python爬虫开发与项目实践-学习笔记(一)
    python之TypeError
    学习笔记-python
    python学习之Unable to locate element
    Chrome浏览器之 webdriver(Chrome version must be >= 63.0.3239.0)
    POJ 1830 开关问题 高斯消元
    HDU 4135 Co-prime 容斥原理
    HDU 1796 How many integers can you find 容斥原理
    卡特兰数,组合数,斯特林数,逆元模板
    HDU 6134 Killer Names 数学 斯特林数
  • 原文地址:https://www.cnblogs.com/Rong-Xiu/p/12701677.html
Copyright © 2020-2023  润新知