0

我正在开发一个 spring ratpack 项目,但我想知道是否有任何方法可以在处理程序之间绑定数据。我尝试使用注册表,但找不到对象仅在一次执行中具有值的方式。我尝试使用 ratpack 会话,但我不想生成会话 cookie 来将该对象持久保存到我的处理程序上。我应该怎么办?我现在迷路了。

这是我的代码配置和持久化对象的方式:

<!-- language: java -->

    //persisting with the SessionModule
    ctx.get(Session.class).getData().then(d -> {
                d.set("email", email);
                ctx.next();
            });

    //Persisting with the registries
            ObjectRegistryComponent objectRegistryComponent = ctx.get(ObjectRegistryComponent.class);
            objectRegistryComponent.setObject(email);
            ctx.next(Registry.single(objectRegistryComponent));
4

1 回答 1

0

我在 ratpack 中发现了一些关于请求的内容,您可以将注册表添加到请求中,这也解决了我的问题。

Request request = ctx.getRequest();
request.add(email);

//--- into your other handlers
String email = ctx.getRequest().get(String.class);
于 2018-03-23T00:42:14.707 回答