restFul风格
restFul风格
传统get方式提交
- url1: http://localhost:8080/findUser?name=tomcat&age=18
- url2: http://localhost:8080/findUser?name=tomcat&age=18&sex=男
需求: 上述的参数传递是否可以简化!
简化写法:
- url3: http://localhost:8080/findUser/tomcat/18/男
restFul风格说明
案例: url3: http://localhost:8080/findUser/tomcat/18/男 (发送)
要求:
- restFul的风格数据的位置一旦确定,不能修改.
- 参数与参数之间使用"/"的方式分割.
- restFul的风格适用于 get/post/put/delete 请求类型
请求类型种类: get/post/put/delete
编辑controllee类
/**
* URL地址:
* http://localhost:8080/findUser/tomcat/18/男 get类型
* 参数: name/age/sex
* 返回值: 返回值获取的数据
* restFul语法:
* 1. 参数与参数之间使用/分割
* 2. 需要接收的参数使用{}包裹
* 3. 参数接收时采用@PathVariable取值
*/
@RequestMapping("/findUser/{name}/{age}/{sex}")
public String findUser(@PathVariable String name,
@PathVariable int age,
@PathVariable String sex){
return name+":"+age+":"+sex;
}
效果