SpringMVC-01 简述

本文详细介绍了SSM框架(SpringMvc、Spring、Mybatis)的概念及其在项目中的应用,重点阐述了SpringMVC的工作流程,包括配置与实现步骤。从客户请求到视图展示的全过程,为读者提供了清晰的SSM开发指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[TOC]

MVC的流程

SSM

SSM:SpringMvc(完成数据的封装,页面的跳转的逻辑)            Spring()            Mybatis(持久化框架。ORM Object Relative Mapping 对象关系映射)

springMVC流程

graph TD A[客户] -->| | B(控制器 Servlet) B --> C( HandlerMapping) C --> D[Controller1] C --> E[Controller1] C -->F[Controller1] D -->G[ModelAndView] E -->G[ModelAndView] F -->G[ModelAndView] G -->H[ ResoluteView] H -->I( 客户)

写一个简单的springMVC的demo

1.引入springmvc的相关jar

**2.在web.xml中配置DispatcherServlet

<servlet>
    <servlet-name>springMVC-annotation</servlet-name>   
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 将springMVC-annotation-servlet放在创建的resource文件中配置的路径 -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springMVC-annotation-servlet.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>springMVC-annotation</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

**3.配置springMVC-annotion的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context"
     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">
     <!-- 包扫描 -->
     <context:component-scan base-package="com.hw.lb.controller.annotation"></context:component-scan>
     <!-- 启动注解器 -->
     <mvc:annotation-driven/> 
     <!-- 配置视图解析器 -->
      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
           <property name="prefix" value="/WEB-INF/view/"/>
           <property name="suffix" value=".jsp"/>
      </bean>
</beans>

SpringMVC的流程

1.客户发出请求。例如 http://localhost:8080/SpringMVC-01/my.do

2.到达web.xml文件中DispatcherServlet.查看是否符合url的要求

3.DispatcherServlet就会查询springmvc的配置文件。(找HandlerMapping)

根据bean的名称查找相应的controller

4.找到我的MyController类。执行该类中handleRequestInternal方法。

5.根据返回的modelAndView在找springmvc配置文件中视图解析器。

6.视图解析器吧viewName和prefix以及suffix做一个拼接,把拼接的页面展示给客户

转载于:https://www.cnblogs.com/DT-Demo/p/11455739.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值