首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从入站网关检索多个查询参数

从入站网关检索多个查询参数
EN

Stack Overflow用户
提问于 2016-05-03 19:06:37
回答 1查看 649关注 0票数 1

我有一个应该为查询参数提供服务并返回响应的配置。这是我的配置。不幸的是,Spring无法创建。

代码语言:javascript
复制
<int-http:inbound-gateway request-channel="inChannel"
        reply-channel="outChannel" supported-methods="GET" 
        path="/ticket">

        <int-http:request-mapping consumes="text/plain" params="param1,param2,param3"
            produces="text/plain" />
</int-http:inbound-gateway>

<int:service-activator ref="ticketIssuingService" method="processTicket"
        input-channel="inChannel" output-channel="outChannel"/>
代码语言:javascript
复制
@MessageEndpoint
public class TicketIssuingService {



    public String processTicket(??? payload){
        System.out.println("Query Paramter String is "+payload);
        return null;
    }
}

m3=duration

如何检索参数以便切换到processTicket方法?Spring抱怨说没有找到合适的方法。processTicket方法的参数应该是什么?请帮帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-03 19:20:07

对于没有GETpayload-expression方法,用于inChannelMessage<?>payload恰好是以下对象:

代码语言:javascript
复制
MultiValueMap<String, String> requestParams = this.convertParameterMap(servletRequest.getParameterMap());

...

        if (payload == null) {
            if (requestBody != null) {
                payload = requestBody;
            }
            else {
                payload = requestParams;
            }
        }

因此,这应该是关于payload服务方法中的processTicket类型的问题的答案。

请注意,您可以通过payload-expression定制该payload-expression,并使用一些内置的SpEL EvaluationContext 变量,例如:

代码语言:javascript
复制
#requestParams - the MultiValueMap from the ServletRequest parameterMap.
#pathVariables - the Map from URI Template placeholders and their values;
#matrixVariables - the Map of MultiValueMap according to Spring MVC Specification. Note, #matrixVariables require Spring MVC 3.2 or higher;
#requestAttributes - the org.springframework.web.context.request.RequestAttributes associated with the current Request;
#requestHeaders - the org.springframework.http.HttpHeaders object from the current Request;
#cookies - the Map<String, Cookie> of javax.servlet.http.Cookie s from the current Request. 

有些示例是这样获得queryString

代码语言:javascript
复制
payload-expression="T(org.springframework.web.context.request.RequestContextHolder).requestAttributes.request.queryString"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37012427

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档