仅做为笔记使用
<form action="http://localhost:2333/test">
<input type="text" name="username">
<input type="submit" value="提交">
</form>
前端表单提交
action :提交的网址
在表单中 “上传文件时“, enctype 格式为multipart/form-data
![](https://img-blog.csdnimg.cn/img_convert/77b3bf9c4f4c8d7fa897324aad9d9b18.png)
后端接收
@Controller
public class testController {
@RequestMapping("/test")
@ResponseBody
public String test( String username){
System.out.println(username);
return username;
}
}
注意
后端接收参数 必须为前端表单提交的name属性
例如
<input type="text" name="username">
name为 username ,则 后端接收参数 必须为 username
Http请求组成
![](https://img-blog.csdnimg.cn/img_convert/942724c9824f0393e7f9023c0b7fc651.png)
Json 请求
![](https://img-blog.csdnimg.cn/img_convert/4529ccd8f4340b81e44ebd05adfdb8cd.png)
请求格式为 josn格式时,需要在后端 加上@RequestBody 注解
@ResponseBody 注解 作用 : 返回时,格式也为josn
json请求时,汉字不需要转码,可直接发送
数据格式小结
![](https://img-blog.csdnimg.cn/img_convert/f278685f5cc6425d909295d459187e0a.png)