什么是 Spring Web MVC?
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, “Spring MVC”,comes from the name of its source module (spring-webmvc)
Spring Web MVC 是基于 Servlet API 构建的原始 Web 框架,从⼀开始就包含在 Spring 框架中。它的正式名称“Spring Web MVC”来⾃其源模块的名称(Spring-webmvc),但它通常被称为“Spring MVC”
MVC
MVC是 Model View Controller 的缩写,它是软件⼯程中的⼀种软件架构设计模式,它把软件系统分为模型、视图和控制器三个基本部分
MVC就是把一个项目分成了三部分
MVC是一种思想,Spring进行了实现,称为Spring MVC
SpringBoot是创建SpringMVC项目的一种方式。
当前阶段,MVC的概念又发生了一些变化,后端开发人员不涉及前端页面的开发,所以也就没有view层,所以view又有了一层解释,之前返回的是视图,现在返回的是视图所需要的数据。
建立连接(客户端和服务器)
@RequestMapping就是建立了路由映射
@RequestMapping可以修饰方法也可以修饰类
访问地址:类的路径+方法路径
http://127.0.0.1:8080/hello/sayhello
@RequestMapping支持get和post
注解如果没有写属性名,默认是value,如下源码:
如果多了属性,比如我们设置必须使用get请求(限制请求方式):
@RequestMapping(value = "/sayhi",method = RequestMethod.GET)
public String sayHi(){
return "hi,SpringBoot!!!";
}
使用postman查看post请求:
请求
请求就是学习如何传参(下命令)
传递单个参数
@RequestMapping("/param")
@RestController
public class ParamController {
@RequestMapping