1.使用IDEA创建Maven工程
2.IDEA配置Maven
3.添加web
(1)右键项目名:“Add Framework Support"
(2)选择WebApplication
(3)核实版本号
(4)核实是否会自动创建web.xml![在这里插入图片描述](https://img-blog.csdnimg.cn/20210414002731817.png#pic_center)
4.引入依赖

```go
<dependencies>
<dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.13.2</version>
       <scope>test</scope>
   </dependency>
   <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-webmvc</artifactId>
       <version>5.2.13.RELEASE</version>
   </dependency>
   <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.5</version>
   </dependency>
   <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>javax.servlet-api</artifactId>
       <version>4.0.1</version>
       <scope>provided</scope>
   </dependency>
</dependencies>
```

5.添加Spring框架的核心配置文件

```go
<?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/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          https://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/mvc
          https://www.springframework.org/schema/mvc/spring-mvc.xsd
      ">

<!-- bean definitions here -->

</beans>
```

6.在Spring的配置文件中配置MVC

```go
<!-- 1加载注解驱动 -->
<mvc:annotation-driven/>
```

7.在controller包下新建HelloController类

```go
package controller;

@Controller
public class HelloController {

@RequestMapping("/hello")
   public String hello(Model model){
       // Model 封装数据
       model.addAttribute("msg","HELLO MY FIRST SPRING MVC PROJECT");

// 返回的字符串就是视图的名字 会被视图解析器处理
       return "hello";
   }
}
```
运行Web项目
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210414234802458.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl81NjMyNTAzOA==,size_16,color_FFFFFF,t_70#pic_center)

 

©著作权归作者所有:来自51CTO博客作者mb6066e453ca35b的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决
  2. 11g 逻辑备库简单故障处理
  3. 为何SYSTEM用户可以将V$SESSION的查询权限赋权给其他用户而SYS用
  4. Django博客开发实战:开篇 | Django学习小组
  5. SpringBoot同时支持多个视图解析器jsp+html+其他模版引擎!
  6. Oracle的告警日志之v$diag_alert_ext视图
  7. 【DB笔试面试697】在Oracle中,V$SESSION视图中有哪些比较实用的列
  8. ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决
  9. 第17章 0304-自己动手写个迷你小框架,学习心得、笔记

随机推荐

  1. 【第767期】你不懂JS:混合(淆)“类”的对象
  2. android binder与handler的简要理解
  3. 【早读汇】广州@mogeWCY的《实战ES2015》
  4. 【第769期】2016 JavaScript 发展现状大
  5. 【早读汇】上海@瑞心扉雪《CSS揭秘》笔记
  6. 【第814期】你不懂JS:ES6与未来 语法(下)
  7. 2016,我做了什么?
  8. Android(安卓)本地代码如何输出日志
  9. RocketMQ 源码分析 —— Message 发送与
  10. 【早读汇】上海@jean-lee《ES6标准入门》