如何使用
准备
小二,上个 DemoController!
来了,客官
@RestController
public class DemoController {
@RequestMapping("list")
public List<User> list(User user, HttpServletRequest request){
String token = request.getHeader("token");
System.out.println("token: "+ token);
System.out.println("查询条件: "+ user);
List<User> users = new ArrayList<>();
User u = new User();
u.setName("张三");
u.setPwd("123456");
u.setAge(1);
users.add(u);
return users;
}
@PostMapping("save")
public String save(@RequestBody User user){
System.out.println("保存成功: "+ user);
return "success";
}
@GetMapping("remove/{id}")
public String remove(@PathVariable Integer id){
System.out.println("删除成功: "+ id);
return "success";
}
}
小二,你这少了点东西!
客官,稍等片刻!
@Data
public class User {
private String name;
private String pwd;
private Integer age;
}
http client
目录结构
Demo.http
### get
GET {{host}}/list?name=zhangsan&pwd=123456&age=12
token:{{token}}
### post
POST {{host}}/list
token:{{token}}
Content-Type: application/x-www-form-urlencoded
name=zhangsan&pwd=123456&age=12
### post json
POST {{host}}/save
token:{{token}}
Content-Type: application/json
{
"name": "张三",
"pwd": "123456",
"age": 1
}
### 删除
GET {{host}}/remove/1
###
环境配置 http-client.env.json
{
"local": {
"host": "http://localhost:8080",
"token": "30846681-b39c-4089-ab74-77d9993d8c8u"
},
"dev": {
"host": "http://xxx.xxx.com:8291",
"token": "30846681-b39c-4089-ab74-77d9993d8c8b"
}
}
如何测试
官方示例
可以针对返回结果,进行测试