我正在开发一个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));
我在 ratpack 中找到了一些关于请求的内容,您可以将注册表添加到请求中,这也解决了我的问题。
Request request = ctx.getRequest();
request.add(email);
//--- into your other handlers
String email = ctx.getRequest().get(String.class);