使用Paypal进行Spring请求映射

时间:2011-11-18 16:02:33

标签: spring jsp paypal

对于返回网址,您似乎必须像这样定义整个网址:

String returnURL = "http://localhost:8080/appName/shopping/confirmorder";

现在,我的请求映射存在问题:

    @RequestMapping(value = "/shopping/confirmorder?token={token}&PayerID={payerID}", method = RequestMethod.GET)
public String doGet(@PathVariable("token") String token, @PathVariable("payerID") String payerID,
        HttpServletRequest request) {

    // do stuff
}

由于某种原因,永远不会调用控制器?

从Paypal返回的最终returnURL是这样的:

http://localhost:8080/appName/shopping/confirmorder?token=EC-4...G&PayerID=A...W

注意Ids已被编辑。

1 个答案:

答案 0 :(得分:1)

如果您有两个名为tokenpayerID的路径变量,那么方法签名应为

public void doGet(@PathVariable("token") String token, 
                  @PathVariable("payerID") String token, 
                  HttpServletRequest request, 
                  HttpServletResponse response)

您是如何期望Spring将这两个字符串放在option类型的int个参数中?

请参阅http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates

此外,PathVariable用于将请求路径的部分绑定到方法参数。在您的情况下,您有请求参数。因此,您应该使用@RequestParam:

@RequestMapping(value = "/shopping/confirmorder", method = RequestMethod.GET)
public void doGet(@RequestParam("token") String token, 
                  @RequestParam("PayerID") String token, 
                  HttpServletRequest request, 
                  HttpServletResponse response)

请参阅http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestparam