官方文档
spring-framework-5.3.8/docs/reference/html/web.html#spring-web

基本介绍
2023年11月15日大约 6 分钟
spring-framework-5.3.8/docs/reference/html/web.html#spring-web
@RequestMapping 注解可以指定控制器/处理器的某个方法的请求的 url,RequestMapping : 请求映射
官方网站:https://www.postman.com/
文档:https://learning.postman.com/docs/getting-started/introduction/
REST:即 Representational State Transfer。(资源)表现层状态转化。是目前流行的请求方式。它结构清晰,很多网站采用。
HTTP 协议里面,四个表示操作方式的动词:GET、POST、PUT、DELETE。它们分别对应 四种基本操作:GET 用来获取资源,POST 用来新建资源,PUT 用来更新资源,DELETE 用来删除资源。
实例
传统的请求方法:
getBook?id=1 GET; delete?id=1 GET; update POST; add POST
传统的 url 是通过参数来说明 crud 的类型,rest 是通过 get/post/put/delete 来说明 crud 的类型。
开发中,如何获取到 http://xxx/url?参数名=参数值&参数名=参数值
package com.lzw.web.requestparam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author LiAng
*/
@RequestMapping("/vote")
@Controller
public class VoteHandler {
/**
* @RequestParam(value = "name", required = false)
* 1. 获取到超链接传递的数据
* 2. @RequestParam 表示会接收提交的参数
* 3. value="name" 表示提交的参数名是name
* 4. required=false 表示该参数可以没有, 默认是true,表示必须有这个参数
* 5. 当我们使用了@RequestParam(value="name", required=false)后就请求的参数名和方法的形参名可以不一致
*/
@RequestMapping(value = "/vote01")
public String test01(@RequestParam(value = "name", required = false) String username) {
System.out.println("得到的 username= " + username); //返回到一个结果
return "success";
}
}