Rest风格支持(使用HTTP请求方式动词来表示对资源的操作)
因为html表单只支持发送get和post请求,所以当发送delete,put请求时,需要设定一个隐藏域,其name值必须为_method,value值为表单的请求方式(且delete,put的表单的method为post请求)。
用法: 表单method=post,隐藏域
首页
# RestFul风格开启,开启支持表单的rest风格
spring:mvc:hiddenmethod:filter:enabled: true
package com.robin.boot.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;@RestController
public class RestTestController {@RequestMapping(value = "/user",method = RequestMethod.GET)public String getUser(){return "GET user , 获取用户成功";}@RequestMapping(value = "/user",method = RequestMethod.POST)public String saveUser(){return "POST user, 保存用户成功";}@RequestMapping(value = "/user",method = RequestMethod.DELETE)public String delUser(){return "DELETE user, 删除用户成功";}@RequestMapping(value = "/user",method = RequestMethod.PUT)public String updateUser(){return "PUT user, 修改用户成功";}}

访问成功,对同一请求/user实现了,不同方式提交的不同处理。



