我已经使用spark创建了一个用于教育目的的api端点。现在,我需要将此实现转换为springboot,并需要使用implementation.Following代码中的application...But参数,展示我是如何实现这两个请求的,如何使用来自spring boot应用程序的请求。下面的实现不会给出请求体。
package com.spark2springboot.application;
import static spark.Spark.*;
public class spark2SpringbootTest {
public static void main(String[] args) {
post("/api/spark2springboot/receive", (request, response) -> {
String str = new String(request.bodyAsBytes());
return str;
});
}
}Spring boot实现
@RestController
public class EmailMessageController {
@PostMapping(path = "/api/spark2springboot/receive", consumes = "application/json", produces = "application/json")
public void spark2springboot(HttpServletRequest request, HttpServletResponse response,) {
String str = CharStreams.toString(request.getReader());
return str;
}
}发布于 2019-08-05 23:14:56
只需引用“https://www.baeldung.com/spring-request-response-body”。更多信息请参考官方文档。
https://stackoverflow.com/questions/57361326
复制相似问题