0
点赞
收藏
分享

微信扫一扫

一、初识 Spring MVC

洛茄 2023-08-13 阅读 50

文章目录



一、初始 Spring MVC


  • 什么是 Spring MVC

  • Spring MVC 的作用

  • Spring MVC 的原理




1.1 回顾 MVC 模式


  • Model(模型):

  • View(视图):

  • Controller(控制器):

  • 职责分析:

    • Controller:控制器

      • 取得表单数据

      • 调用业务逻辑

      • 转向指定的页面

    • Model:模型

      • 业务逻辑

      • 保存数据的状态

    • View:视图

      • 显示页面

  • MVC 模式的主要作用: 降低视图与业务逻辑之间的双向耦合

最典型的 MVC 就是 JSP + servlet + javabean 的模式。




1.2 回顾 Servlet


  • 代码示例

    • 创建 maven 项目,以此项目为父项目,在父项目的 pom.xml 中导入相关依赖

      <dependencies>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.12</version>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-webmvc</artifactId>
             <version>5.1.9.RELEASE</version>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <version>2.5</version>
         </dependency>
         <dependency>
             <groupId>javax.servlet.jsp</groupId>
             <artifactId>jsp-api</artifactId>
             <version>2.2</version>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jstl</artifactId>
             <version>1.2</version>
         </dependency>
      </dependencies>
      
  • 在父项目上右键创建子项目,创建完成之后,在子项目上右键选中 Add framework support 找到 Web Application 勾选上

    • 具体步骤

    • 勾选完之后项目会出现 web 目录

举报

相关推荐

0 条评论