Mvc第一天
今天目标就是将所有的接口相关的注解理解,并且所有的注解都举例写出代码(cdsn上查)
1 mvc的基本概念:
 
mvc: model,view,Controller,简单解释就是模型,视图,控制器.面试会问,md文档这些描述很到位,你可以看看

2 接口注解:
(1) @Controller/RestController表示当前类是一个接口类,里面的方法可以使用 @GetMapping.@PostMapping等注解标识,然后共给外部直接使用
接口注解的衍生关系,在最终还是@Compent注解标注的

(2) 接口注解 @RequestMapping,提供路由的,默认是get请求,这个下面还有其他的衍生注解,衍生注解只能使用于方法,但是这个注解可以使用在方法和类上
标注类: 顶层路由
@RestController
@RequestMapping("test")
public class ControllerDemo {
    @RequestMapping
    public void  test(){}
}标注方法: 不指定请求格式,则默认是get,

标注方法: 注意仔细看代码中的描述
package com.example.springdemo.mvc.demo1;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("test")
public class ControllerDemo {
    @RequestMapping("/test1")
    public void test() {
    }
    @RequestMapping(value = "/test2",method = RequestMethod.PUT)
    public void test2() {
    }
    @RequestMapping(value = "/test3",method = RequestMethod.POST)
    public void test3() {
    }
    /**
     请求还有其他的方式,get和post常用,其他的根据和前端约定的情况进行`处理,但是要注意,除了get请求,其他都是post请求衍生的,可以传递json数据,get只能传递一般数据
     GET,
     HEAD,
     POST,
     PUT, 
     PATCH,
     DELETE,
     OPTIONS,
     TRACE;
     */
    
    
    /**
     * get和post
     * 传递数据的区别在于post有请求体,get没有请求体,json数据只能在请求体中存放,所以get请求不可以传递json数据
     */
}
(3) 相应数据格式转换@ResponseBody注解就是后端相应给前端的对象数据转换为json格式的,在SpringBoot的web包中已经带你看过了的,回顾一下
可以使用在方法和controller类上
这个注解衍生的注解@RestController(ResponseBody注解和Controller注解组成)
RestFul接口注解:
简单解释:
这种只是一种风格,并不是一种规范,也即是可以不使用,主要看项目约定
RequestMapping风格对比:
  



















