我想使用 Spring Boot 从收到的 html 请求正文中获取正文值: @PostMapping(value = "/v1/notification") public ResponseEntity<String> handleNotifications( @RequestParam(value = "uniqueid", required = false)) String uniqueidValue, @RequestParam(value = "type", required = false)) String statusValue) { // Get values from html body return new ResponseEntity<>(HttpStatus.OK); }例如,当我收到通知正文时:some_key=some_value&sec_key=sec_value我想解析这些值。我该如何实施?
1 回答
弑天下
TA贡献1818条经验 获得超8个赞
您可以使用 Map 和 @RequestBody 来获取键值对请求,如下所示:
@PostMapping(value = "/v1/notification")
public ResponseEntity handleNotifications(@RequestBody Map<String,String> keyValuePairs) {
// here you can use keyValuePairs
// you can process some specific key like
String value = keyValuePairs.get("someSpecificKey");
return ResponseEntity.ok(value);
}
在这里,我附上邮递员请求示例:
添加回答
举报
0/150
提交
取消