三层架构、Mvc配置

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

三层架构

   数据层
        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

引包:

springmvc
springcontext
javax.servlet
javax.servlet.jsp.jstl
javax.servlet.jsp
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.1.3.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
    <dependency>
      <groupId>org.springframework</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.xml(名字自己随便起)

<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.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:annotation-config/> <!--开启注解模式-->
    <context:component-scan base-package="com.sun"/> <!--管理对象路径-->
    <mvc:annotation-driven/> <!--开启MVC注解模式-->
</beans>
import org.springframework.stereotype.Controller;
import org.springframework.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 有的都可以获得
        // 表单获得变得简单 说明类型 及名称就可以获得表单数据
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章