整合SpringMVC


1、MVC中:M-----模型(model)   v---视图(view)(jsp)    c-----控制器(Controller 相当于 servlet)

2、项目的架构是演进的

3、Controller控制器的功能:

     《1》取得表单数据;

     《2》调用业务逻辑;

     《3》转向指定的页面

Model的功能:

    《1》业务逻辑

    《2》保存数据的状态

View的功能:

    显示页面

4、视图解析器的作用:

    《1》获取ModelAndView的数据;

    《2》解析ModelAndView的视图名字

    《3》拼接视图名字,找到对应的视图

    《4》将数据渲染到视图上;

5、MVC框架要做哪些事情:

《1》将URL映射到java类或java类方法(请求)

《2》封装用户提交的数据;

《3》处理请求------调用相关的业务处理------封装响应数据

《4》将响应的 数据进行渲染    .jsp/html等表示层数据

 

6、具体实现步骤(用注解)

步骤1:加入依赖

步骤2:配置web.xml

 
 
    
        springmvc
        class>org.springframework.web.servlet.DispatcherServletclass>
       
        
            contextConfigLocation
            classpath:springmvc.xml
        
        
        1
    

    
        springmvc
        /
    

 注意:在springmvc中  /  和  /*   的区别:

          《1》/   表示匹配所有的请求,不会去匹配jsp页面

          《2》/*   表示会匹配所有的请求包括jsp页面

步骤3:创建springmvc的配置文件sppringmvc.xml(在resources文件夹中创建)

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>

       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.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.xsd">
    
    package="com.itheima.controller"/>
    
    default-servlet-handler/>
    
    
 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"  id="internalResourceViewResolver">
        
        
      
        

    

步骤4:举例说明:

相关