从接收到的HTML正文中获取值

时间:2018-08-10 20:04:28

标签: java spring spring-boot

我想使用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 个答案:

答案 0 :(得分:1)

您可以使用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);
}

在此附上示例邮递员请求:enter image description here