如何在Spring Controller中检索FORM / POST参数? [英] How to retrieve FORM/POST Parameters in Spring Controller?

查看:152
本文介绍了如何在Spring Controller中检索FORM / POST参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的响应应该来自 MailChimp webhook网址。

I have the following response that should come from a MailChimp webhook URL.

这是行BODY:

RAW BODY

    type=usub&fired_at=2015-07-23+17%3A19%3A34&data%5Baction%5D=unsub&data%5Breason%5D=manual&data%5Bid%5D=9383uy636&data%5Bemail%5D=youremail%40YOURDOMAIN.com&data%5Bemail_type%5D=html&data%5Bip_opt%5D=202.9.3.003&data%5Bweb_id%5D=404004&data%5Bmerges%5D%5BEMAIL%5D=YOUREMAIL%40YOURDOMAIN.com&data%5Bmerges%5D%5BFNAME%5D=NAME&data%5Bmerges%5D%5BLNAME%5D=LASTNAME&data%5Blist_id%5D=2288883
 FORM/POST PARAMETERS

fired_at: 2015-07-22 12:19:34
data[email]: YOUREMAIL@DOMAINNAME.com
data[id]: 56775409ta
data[web_id]: 09833944
data[merges][EMAIL]: YOUREMAIL@DOMAINNAME.com
type: unsub
data[list_id]: 99884hy372
data[merges][FNAME]: Name
data[ip_opt]: 202.0.9.3333
data[reason]: manual
data[email_type]: html
data[action]: unsub
data[merges][LNAME]: LastName

**QUERYSTRING key: a4483983hu473004884j0x**

HEADERS

Accept: */*
Total-Route-Time: 0
Host: requestb.in
Connection: close
Content-Length: 395
User-Agent: MailChimp.com
Connect-Time: 0
Via: 1.1 vegur
X-Request-Id: 6633d8-653e-4cea-884j-9933ju4773h
Content-Type: application/x-www-form-urlencoded

我用过 @RequestParameter 之前在使用Spring Controllers时,我不知道如何从上面的响应中获取数据,例如数据[merges] [FNAME]

I have used @RequestParameter previously when working with Spring Controllers, however I am not sure how to get the data from the above response for e.g data[merges][FNAME]:

如何在Spring控制器中获取QueryString? QUERYSTRING键:a4483983hu473004884j0x

How can I also get the QueryString inside a Spring controller ? QUERYSTRING key: a4483983hu473004884j0x

//I have the following code to begin with
@RequestMapping("/unsubscribewebhook")
    public ZapJasonMessage unsubscribeWebHook(
    @RequestParam("key") String key,
    @RequestParam ("data[merges][FNAME]") String firstName
) {

}

感谢您的帮助!

推荐答案

您只需将WebRequest作为参数注入控制器POST方法,然后请求getParameter(),并使用给定的参数Mailchimp webhook。

You just need to inject WebRequest as a parameter into your controller POST method, and then ask for getParameter(), with a given parameter from the Mailchimp webhook.

例如:

@RequestMapping(path="/MyUrl", method=RequestMethod.POST)
public ModelAndView process(WebRequest request){
    System.out.println(request.getParameter("type"));
    System.out.println(request.getParameter("data[merges][EMAIL]"));
    return new ModelAndView([YOURVIEWHERE]);
}

这就是...

问候。

这篇关于如何在Spring Controller中检索FORM / POST参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆