SpringBoot接口开发

依赖的jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.0.0.RELEASE</version>
</parent>
注解:
1. @RequestMapping:@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
- @GetMapping:@GetMapping("/get/{id}");@GetMapping是一个作为快捷方式的组合注释相当于@RequestMapping(method = RequestMethod.GET)
- @PostMapping:@PostMapping是一个作为快捷方式的组合注释相当于@RequestMapping(method = RequestMethod.POST)
- @PutMapping
- @DeleteMapping
- @PatchMapping
说明:@GetMapping是一个作为快捷方式的组合注释相当于@RequestMapping(method = RequestMethod.GET)
例子:

请求参数:
@RequestParam 和 @PathVariable 区别
@RequestParam 和 @PathVariable 注解是用于从request中接收请求的,两个都可以接收参数关键点不同的是@RequestParam 是从request里面拿取值,而 @PathVariable 是从一个URI模板里面来填充
例如:访问地址格式为:url:port/get/with/param/10/20

访问地址格式为:url:port/get/with/param?key=value&key=value


@ResponseBody
responseBody表示服务器返回的时候以一种什么样的方式进行返回, 将内容或对象作为 HTTP 响应正文返回,值有很多,一般设定为json
@RequestBody
一般是post请求的时候才会使用这个请求,把参数丢在requestbody里面

posted @   王广福  阅读(201)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示