当前位置: 首页> 健康> 美食 > 第十四节:学习Springboot 的restful接口风格(自学Spring boot 3.x的第三天)

第十四节:学习Springboot 的restful接口风格(自学Spring boot 3.x的第三天)

时间:2025/8/23 9:15:45来源:https://blog.csdn.net/qq_21004057/article/details/141833446 浏览次数:0次

这节记录下自己学习restful的记录。

  • 增(PostMapping)
    /*** 保存学生* @return*/@PostMappingpublic Student save(@RequestBody Student student){studentService.save(student);return student;}

注意:传参使用RequestBody

  • 删(DeleteMapping)
 /*** 删除学生信息* @param id*/@DeleteMapping("/{id}")public void deleteById(@PathVariable Integer id){studentService.deleteById(id);}

注意:通过@PathVariable 方式传参删除

  • 改(PutMapping)
/*** 更新学生信息* @param student* @return*/@PutMappingpublic Student update(@RequestBody  Student student){student.setCreate_time(new Date());studentService.updateById(student);return student;}

注意:通过@PutMapping方式传参更新

  • 查所有学生信息(GetMapping)
   /*** 查询所有学生信息* @return*/@GetMappingpublic List<Student> list(){return  studentService.list();}
  • 通过id查询学生信息(GetMapping)
 /*** 通过id查询指定学生信息* @param id* @return*/@GetMapping("/{id}")public Student getById(@PathVariable Integer id){return studentService.getById(id);}

注意:通过@PathVariable 方式传参更新

关键字:第十四节:学习Springboot 的restful接口风格(自学Spring boot 3.x的第三天)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: