SpringBoot使用PostMan访问测试效果

2022-08-20 14:39:34

测试环境

下载Postman测试软件https://www.postman.com/downloads/
在这里插入图片描述

项目测试

测试StudentController中的所有方法,注意提交方式的对应。

1.查询所有学生对象

	@GetMappingpublic List<Student>listAllStudents(){return studentService.queryAllStudents();}

在这里插入图片描述

2.查询单个学生对象

将参数绑定在路径上@PathVariable。

	@GetMapping("/{id}")public StudentloadStudentById(@PathVariable int id){return studentService.queryOneById(id);}

在这里插入图片描述

3.添加单个学生对象

将参数绑定在请求体上@RequestBody。

	@PostMappingpublic booleanaddStudent(@RequestBody Student student){return studentService.addStudent(student);}

在这里插入图片描述
数据库:
在这里插入图片描述

4.修改学生对象

将参数绑定在请求体上@RequestBody。

	@PostMappingpublic booleanaddStudent(@RequestBody Student student){return studentService.addStudent(student);}

在这里插入图片描述
数据库:
在这里插入图片描述

5.删除学生对象

将参数绑定在路径上@PathVariable。

	@DeleteMapping("{id}")public booleandeleteStudentById(@PathVariable int id){return studentService.deleteStudentById(id);}

在这里插入图片描述
数据库:
在这里插入图片描述

参考:

postman+springboot传参

  • 作者:crazyblackkk
  • 原文链接:https://blog.csdn.net/weixin_45266846/article/details/119294496
    更新时间:2022-08-20 14:39:34