SpringMVC 请求体接收任意格式参数

SpringMVC Spring Boot About 550 words

需求

Spring Controller作为网关,或者只需透传,将接收到的数据直接发送到下游。

String

使用String接收@RequestBody请求体。

@Slf4j
@RestController
public class ProxyController {

    @RequestMapping("/proxy")
    public String proxy(@RequestBody(required = false) String body) {
        return "";
    }

}

JsonNode

使用jackson中提供的JsonNode对象,接收Content-Typeapplication/json的请求体。

JsonNode能接收Json对象和Json数组。

@Slf4j
@RestController
public class ProxyController {

    @RequestMapping("/proxy")
    public JsonNode proxy(@RequestBody(required = false) JsonNode body) {
        return body;
    }

}
Views: 1,292 · Posted: 2022-10-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh