在 Spring Boot 中使用 GET 方法接收 JSON 数据,需要在控制器的方法上使用 @RequestMapping(method = RequestMethod.GET) 指定请求方法为 GET,并使用 @RequestBody 注解来接收 JSON 数据。
示例代码如下:
@RestController
public class ExampleController {
@RequestMapping(value = "/example", method = RequestMethod.GET)
public void receiveJson(@RequestBody ExampleData data) {
// do something with the JSON data
}
}
其中 ExampleData 是一个 POJO 类,用来存储 JSON 数据。
注意:使用 GET 方法接收 JSON 数据并不是一个常用做法,一般都是使用 POST 方法。