小编odd*_*per的帖子

Spring Reactive 使用 ServerRequest 获取主体 JSONObject

我是春季反应新手。

我正在尝试使用邮递员从服务器获取请求信息。

首先,邮递员使用 post 方法向服务器发送信息。其次,我们一直在使用相关代码在服务器端工作并获取请求信息。

在下面的代码片段中

不知道能不能拿到ServerRequest函数的JSONObject。

邮递员身体(应用程序/ json)

{
    "name": "aaaa",
    "name_order": ["aa", "bb", "cc"],
    "type": "12",
    "query": ""
}
Run Code Online (Sandbox Code Playgroud)

java (RouterFunction)

import com.ntels.io.input.handler.RestInHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.function.server.*;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
import static org.springframework.web.reactive.function.server.RequestPredicates.PUT;
import static org.springframework.web.reactive.function.server.RequestPredicates.DELETE;

@Configuration
@EnableWebFlux
public class RestConfig implements WebFluxConfigurer {

    @Bean
    public RouterFunction<ServerResponse> routes(RestInHandler restInHandler){
        return RouterFunctions.route(POST("/input/event").
        and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), restInHandler::toRESTInVerticle);
    }
}
Run Code Online (Sandbox Code Playgroud)

java(处理程序)

public Mono<ServerResponse> toRESTInVerticle(ServerRequest serverRequest) {
    String serverRequestUrl = serverRequest.uri().toString();

    System.out.println("RestInHandler test …
Run Code Online (Sandbox Code Playgroud)

java spring reactive

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

reactive ×1

spring ×1