三层架构好处将每个部分都独立开,方便升级扩展

三层架构

   数据层        1.负责所有对象数据操作的方法        2.对数据连接处理        3.对外绝对不暴露任何sql语句   业务层        1.事务处理        2.业务处理   视图层        mvc结构              M 与业务层接轨处              C 控制器              V JSP数据呈现    MVC:        模型 M 业务调用,业务层调用        控制器  C 接受请求找到模型,得到模型结果,跳转至相应页面        视图 v 呈现数据 

请求过程 1、V>>>C>>>M>>>C>>>V 这个常用 因为所有都是由控制器来操作 视图不和逻辑交互

   2、  V>>>C>>>M>>>V

引包:

springmvcspringcontextjavax.servletjavax.servlet.jsp.jstljavax.servlet.jsp
    <dependency>      <groupId>org.spring work</groupId>      <artifactId>spring-webmvc</artifactId>      <version>5.1.3.RELEASE</version>    </dependency>    <!-- https://mvnrepository.com/artifact/org.spring work/spring-context -->    <dependency>      <groupId>org.spring work</groupId>      <artifactId>spring-context</artifactId>      <version>5.1.3.RELEASE</version>    </dependency>    <dependency>      <groupId>javax.servlet</groupId>      <artifactId>javax.servlet-api</artifactId>      <version>3.1.0</version>      <scope>provided</scope>    </dependency>    <dependency>      <groupId>javax.servlet.jsp.jstl</groupId>      <artifactId>jstl</artifactId>      <version>1.2</version>    </dependency>    <dependency>      <groupId>javax.servlet.jsp</groupId>      <artifactId>jsp-api</artifactId>      <version>2.2</version>      <scope>provided</scope>    </dependency>

配置resources
Application. (名字自己随便起)

<beans  ns="http://www.spring work.org/schema/beans"        ns:xsi="http://www.w3.org/2001/ Schema-instance"        ns:context="http://www.spring work.org/schema/context"        ns:mvc="http://www.spring work.org/schema/mvc"       xsi:schemaLocation="http://www.spring work.org/schema/beans http://www.spring work.org/schema/beans/spring-beans.xsd http://www.spring work.org/schema/context http://www.spring work.org/schema/context/spring-context.xsd http://www.spring work.org/schema/mvc http://www.spring work.org/schema/mvc/spring-mvc.xsd">    <context:annotation-config/> <!--开启注解模式-->    <context:component-scan  -package="com.sun"/> <!--管理对象路径-->    <mvc:annotation-driven/> <!--开启MVC注解模式--></beans>
import org.spring work.stereotype.Controller;import org.spring work.web.bind.annotation.RequestMapping;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;@Controller //所明这个类是控制器 要想管理servlet就得将他们集中起来进行统一的管理 public class Action {    @RequestMapping("/hello")//和webServlet作用一样    public void Method(int password,                       String uname, HttpServletRequest request,                       HttpServletResponse response,                       HttpSession session) {       //这里获得的是 HttpServletRequest请求头,HttpServletResponse响应头        //servlet 有的都可以获得        // 表单获得变得简单 说明类型 及名称就可以获得表单数据    }}
收藏 打印