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里面

浙公网安备 33010602011771号