入门

创建SpringBoot工程,勾选web开发相关依赖。

package com.example;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController//这个注解是用来将一个类声明为一个控制器,并将其中的方法映射到HTTP请求。
public class controller {
    @RequestMapping("/hello")//这个注解是用来映射HTTP请求的。网页访问http://localhost:8080/hello,就会调用hello()方法并返回"Hello World!"。
    public String hello() {
        System.out.println("Hello World!");
        return "Hello World!";
    }
}

HTTP协议

请求协议

SpringBootWeb_spring

SpringBootWeb_spring_02

SpringBootWeb_spring_03

响应格式

SpringBootWeb_spring_04

SpringBootWeb_HTTP_05

SpringBootWeb_HTTP_06

200 404 500

协议解析

不用学,有现成的。