注:如果同一个项目两种restful请求格式相同的话,会产生请求模糊异常。
package com.springboot.controller;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* @author dc
* @date 2020/5/11 - 20:12
*/
@RestController
public class StudentController {
/*这3种方法均为restful请求风格,形成2组对比
* 1与2对比,1与3对比,1与2对比说明请求形式可区分restful
* 1与3对比说明请求数据格式可区分restful*/
@GetMapping("/student/detail/{id}/{age}")
public Object doFirst(@PathVariable("id") Integer id,
@PathVariable("age") Integer age){
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("age", age);
return map;
}
@PostMapping("/student/detail/{id}/{status}")
public Object doSecond(@PathVariable("id") Integer id,
@PathVariable("status") Integer status){
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("status", status);
return map;
}
@GetMapping("/student/{id}/detail/{city}")
public Object doThird(@PathVariable("id") Integer id,
@PathVariable("city") Integer city){
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("city", city);
return map;
}
}