前面5个是一个输入一个输出的

项目中使用得到:



public static Mono<ServerResponse> dynamicMono(Mono<JSONObject> inJsonObjMono,
                                                   Function<JSONObject, Mono<JSONObject>> funService,
                                                   String... judgeParams) {

        return inJsonObjMono.publishOn(Schedulers.parallel()).flatMap(
                json -> {
                    if (judgeParams != null) {
                        for (int i = 0; i < judgeParams.length; i++) {
                            if (json.get(judgeParams[i]) == null) {
                                return ServerResponseBuild.badRequestMsg(judgeParams[i] + "必传");
                            }
                        }
                    }
                    Mono<JSONObject> jsonObjectMono = funService.apply(json);
                    return jsonObjectMono.flatMap(
                            resultJson -> {
                                if (resultJson.getInteger("errcode") != 0) {
                                    return ServerResponseBuild.badRequestMsg(json.getString("errmsg"));
                                }
                                log.info("
返回数据:{}", resultJson);
                                return ServerResponseBuild.okRequestObj(resultJson, JSONObject.class);
                            }
                    ).switchIfEmpty(ServerResponseBuild.badRequestMsg("请求错误")
                    ).onErrorStop();
                }
        ).switchIfEmpty(
                ServerResponseBuild.badRequestMsg("参数错误")
        );
    }

后面是两个函数的

原文地址:https://www.cnblogs.com/ukzq/p/13844051.html