提交 24f7f26f 编写于 作者: A Arjen Poutsma

Add RenderingResponse.from

This commit introduces RenderingResponse.from(RenderingResponse),
allowing for easier response filtering.
上级 54abda5e
......@@ -46,6 +46,20 @@ public interface RenderingResponse extends ServerResponse {
// Builder
/**
* Create a builder with the template name, status code, headers and model of the given response.
* @param other the response to copy the values from
* @return the created builder
*/
static Builder from(RenderingResponse other) {
Assert.notNull(other, "'other' must not be null");
DefaultRenderingResponseBuilder builder = new DefaultRenderingResponseBuilder(other.name());
builder.status(other.statusCode());
builder.headers(other.headers());
builder.modelAttributes(other.model());
return builder;
}
/**
* Create a builder with the given template name.
* @param name the name of the template to render
......
......@@ -56,14 +56,9 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
RouterFunction<RenderingResponse> normalRoute = route(GET("/normal"), handler::render);
RouterFunction<RenderingResponse> filteredRoute = route(GET("/filter"), handler::render)
.filter(ofResponseProcessor(
response -> {
Map<String, Object> model = new LinkedHashMap<>(response.model());
model.put("qux", "quux");
return RenderingResponse.create(response.name())
.modelAttributes(model)
.build();
}));
response -> RenderingResponse.from(response)
.modelAttribute("qux", "quux")
.build()));
return normalRoute.and(filteredRoute);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册