我们在开发中很常见的一种方式是通过请求的类型,也就是restful风格来区别我们的请求接口。
通过请求类型的不同(GET POST PUT DELETE) 来区分即便是请求路径相同的请求。
但是他的底层是如何支持的呢,明明我请求路径都是/user。就因为类型不同就能区分到不同的接口。
接下来我们就看看这部分实现。从这个实现开始,我们将会彻底打通关于springboot中的请求处理的所有原理。
一、准备测试代码
1、简易前端
我的前端属于是菜的不能再菜那种,这里我们就实现四个简单的提交表单,用来调用我们的四个接口,从而观察现象。
我们把这个html文件命名为restfulForm.html放在我们的静态资源目录下面。
页面的代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 600px;
margin: auto;
}
form {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 5px;
font-weight: bold;
}
input, textarea {
margin-bottom: 15px;
padding: 8px;
font-size: 16px;
}
button {
padding: 10px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>Test Form</h1>
<form action="/user" method="get">
<input value="get提交" type="submit">
</form>
<form