我想使用HttpRequestHandlingMessagingGateway::setPayloadExpression
将请求值映射到我的模型对象。我找到了this answer,但没有设法用java配置做同样的事情。如果有人可以提供一个例子,它会很棒。
我的代码:
@Bean
public HttpRequestHandlingMessagingGateway httpViewGate() {
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
RequestMapping requestMapping = new RequestMapping();
requestMapping.setMethods(HttpMethod.GET);
requestMapping.setPathPatterns("/foo");
requestMapping.setProduces(MediaType.APPLICATION_JSON_VALUE);
gateway.setRequestMapping(requestMapping);
gateway.setRequestChannel(intConfig.viewFlowRequestChannel());
gateway.setPayloadExpression(???); //what to do here
gateway.setRequestPayloadType(ViewClientCriteria.class);// this may not be required
return gateway;
}
我也很感兴趣,还有另一种更灵活的方式来做同样的事情。
我使用Spring Boot 1.2.4
答案 0 :(得分:1)
Expression payloadExpression = new SpelExpressionParser().parseExpression("...");
gateway.setPayloadExpression(payloadExpression);