系列文章目录
第一章 MVC模式
第二章 让程序run起来
第三章 @Controller、@RequestMapping 注解和获取请求参数
第四章 域对象、视图、转发和重定向
第五章 第五章 实现RESTful
第六章 MVC类型转换器、格式化器
第七章 JSON数据交互
第八章 拦截器实现权限验证、异常处理
第九章 文件上传、下载
第十章 使用logback+Slf4j打印日志
第十一章 单体架构任务调度
文章目录
前言
教授大家如何实现RESTful
1、什么是RESTful
resource Representational State Transfer 的缩写,就是“表现层资源表述状态转移”
1.1、Resource(资源)
web应用的文件,uri定位
1.2、Representation(资源的描述)
html、xml、json等
1.3、State Transfer(状态转移)
2、RESTful 规则
URL 只用来标识和定位资源
当请求中需要携带参数时,RESTFul 允许我们将参数通过斜杠(/)拼接到 URL 中
HTTP 协议中有四个表示操作方式的动词:GET、POST、PUT 和 DELETE,它们分别对应了四种与资源相关的基本操作
3、Spring MVC
3.1、服务端实现RESTful接口
从传统的 http://www.xxx.com?user/testRest/id=101&username=zhangsan,变为: http://www.xxx.com/user/testRest/101/zhangsan
@RequestMapping("/testRest/{id}/{username}")
public String testRest(@PathVariable("id") String id, @PathVariable("username")
设置get post put delete请求方式
@RequestMapping(value = "/login", method = RequestMethod.PUT)
3.1、前端请求
thymeleaf 表单
<form th:action="@{/login}" method="post">