Spring的核心IOC+DI AOP 注解
V:
C: 请求 响应 SpringMVC(请求的分析过程—控制层的请求分发) Spring对象的管理
M: Service
DAO MyBatis(JDBC)
=================================================
1.浏览器发送请求(String)
2.到达服务端
3.服务端接收请求(String)
4.服务端解析请求(String 请求名字 参数 。。。。)
5.参考配置文件 Tomcat中的那个文件 web.xml
文件中配置了 请求—-真实类(Servlet)之间的关系
6.通过参考配置文件找到了一个Servlet
Servlet不能随意写,需要遵循规则
继承HttpServlet
重写service/doPost/doGet
参数HttpServletRequest HttpServletResponse
异常ServletException IOException
方法内部做的事情 取参数 找业务 给响应
7.响应回去,浏览器再解析,展示
——————————————————————————-
以上这个是最基本的请求与响应流程
出现了Servlet问题
Servlet需要遵循很多的规则(Tomcat)
一个请求(功能点)直接对应一个Servlet类
每一个Servlet类还需要配置一个信息 8行 1行
自己在这个问题出现的时候做了一个封装WEB框架
一个请求 对应 一个类
一个请求 对应 一个类中的某一个方法
所有的Servlet请求先到达一个统一的位置DispatcherServlet
这个类的目的是为了分析请求的类名及方法名
根据类名和方法名找到具体执行的方法,从而执行
*.do
xml核心文件中就做一次配置就可以啦
DispatcherServlet
.do
——————————————————————————-
DispatcherServlet
Handler启动时候读取配置文件 解析 。。。
1.接收信息 类名 方法名 参数
2.通过类名及方法名找资源(真实的Servlet—-已经没有规则啦)
类名+方法名———真实类下的方法对应关系???
配置.properties 注解@RequestMapping
3.可以发送请求
找到一个真实类中的方法Servlet类的方法
取值(参数) 找业务 存储数据 响应信息
不想出现任何跟原来有关系的变量 request response
IOC+DI
参数 正常变量即可
返回值 String ModelAndView
================================================================================
自己封装的MVC小框架怎么用来着?
1.下载 导包
2.核心配置文件 web.xml
DispatcherServlet
.do
3.自己写正常的控制层代码(Servlet没有规则)
不需要继承
不需要重写 方法名自定义
参数不需要request response 参数目的是为了接收请求信息 请求中的key对应即可
不需要异常
方法里面正常做事 ModelAndView @ResponseBody @SessionAttributes
4.发送请求的时候
请求的名字——类中方法直接对应
Servlet的方法的上面直接添加注解@RequestMapping(“xxx.do”)
/按照路径来匹配的——当前工程 jsp html servlet
.do按照请求的资源类型匹配的
Filter —- 拦截器
———————————————————————————-
参考如上的用法来大概猜测—-尝试搭建SpringMVC — 需要基于Spring使用,不能单独使用
1.下载
2.导包 基于spring原有的包 core contenxt beans expression
commons-logging
基础上多导3个包 web webmvc aop
3.核心配置文件 web.xml
DispatcherServlet
*.do
4.自己写控制层类啦
是否有规则?
。。。。
参数如何接收 单个 map domain 要不要注解
如何存储 request.setAttribute();
响应信息 String ModelAndView JSON
拦截器 文件上传下载
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><servlet><servlet-name>mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:ApplicationContext.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>mvc</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping></web-app>
package controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.servlet.ModelAndView;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/*** 1.继承HttpServlet 实现Controller* 2.重写service 重写* 3.两个参数 req resp 参数* 4.两个异常 serv io 异常* 5.没有返回值 void 返回值ModelAndView** 正常情况下 按照普通类来对待即可* 没有继承 方法自定义 方法参数跟请求的key一致即可 参数普通类型 domain类型 map类型** 配置(xml 注解)* 1.将这个Controller类的对象交个Spring当做Bean管理起来 @Controller* 2.请求和这个类及方法对应上才可以** web-inf 文件 mvc-servlet.xml*/@Controllerpublic class TestController{@RequestMapping("test.do")public void test(String name){System.out.println("执行啦"+name);}}
<?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/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--<bean id="testController" class="controller.TestController"></bean>--><context:component-scan base-package="controller"></context:component-scan><!--启动一个Handler小弟 解析 类映射关系。。。。--><!--<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">--><!--<property name="mappings">--><!--<props>--><!--<prop key="test.do">testController</prop>--><!--</props>--><!--</property>--><!--</bean>--><!--先去做一个底层小弟Handler的加载--><mvc:annotation-driven></mvc:annotation-driven></beans>
<%--Created by IntelliJ IDEA.User: AdministratorDate: 2021/5/26Time: 22:09To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head><title>$Title$</title></head><body><a href="test.do?name=zzt">测试一下</a></body></html>
