Java 对spring MVC控制器的出站网关post请求
我尝试通过出站网关将类型为多值映射的有效负载发送到spring MVC控制器。但似乎地图数据没有到达控制器。不知道什么是错的或缺失的。我的代码是这样的: 出站配置:Java 对spring MVC控制器的出站网关post请求,java,spring,spring-mvc,spring-integration,Java,Spring,Spring Mvc,Spring Integration,我尝试通过出站网关将类型为多值映射的有效负载发送到spring MVC控制器。但似乎地图数据没有到达控制器。不知道什么是错的或缺失的。我的代码是这样的: 出站配置: <int-http:outbound-gateway id="outGateway" http-method="POST" request-channel="responseChannel" url="http://localhost:8081/SpringIntegration-In-out-tes
<int-http:outbound-gateway id="outGateway"
http-method="POST"
request-channel="responseChannel"
url="http://localhost:8081/SpringIntegration-In-out-test/responseReq"
extract-request-payload="true">
</int-http:outbound-gateway>
@RequestMapping("/responseReq")
public ModelAndView goResponse(@RequestBody MultiValueMap<String,String> body){
Iterator it = body.entrySet().iterator();
while (it.hasNext()) {
MultiValueMap.Entry pairs = (MultiValueMap.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
it.remove();
}
return new ModelAndView("response");
}
控制器配置:
<int-http:outbound-gateway id="outGateway"
http-method="POST"
request-channel="responseChannel"
url="http://localhost:8081/SpringIntegration-In-out-test/responseReq"
extract-request-payload="true">
</int-http:outbound-gateway>
@RequestMapping("/responseReq")
public ModelAndView goResponse(@RequestBody MultiValueMap<String,String> body){
Iterator it = body.entrySet().iterator();
while (it.hasNext()) {
MultiValueMap.Entry pairs = (MultiValueMap.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
it.remove();
}
return new ModelAndView("response");
}
@RequestMapping(“/responseReq”)
公共模型和视图goResponse(@RequestBody多值映射体){
迭代器it=body.entrySet().Iterator();
while(it.hasNext()){
MultiValueMap.Entry pairs=(MultiValueMap.Entry)it.next();
System.out.println(pairs.getKey()+“=”+pairs.getValue());
it.remove();
}
返回新的ModelAndView(“响应”);
}
我使用迭代器来获取映射值,但它什么都没有。一切看起来都不错
Map
作为有效负载控制器
,例如使用一些RestClient。我的偏好-。在此处手动构建表单,表单应转换为DispatcherServlet
中的多值映射,不要忘记显示标题内容类型:application/x-www-form-urlencoded
如果出站适配器将以单向方式使用(仅发送),则应使用
出站通道适配器
:
<int-http:outbound-channel-adapter
id="outAdapter"
channel="responseChannel"
url="http://localhost:8081/SpringIntegration-In-out-test/responseReq"
http-method="POST"
charset="UTF-8"
/>
最后,为什么要通过设置extract-request-payload=“true”
将Spring集成消息转换为JMS消息