2017-09-15 44 views
1

我在使用Spring解析URL时遇到问题。 我的终点是春天 - 查询参数没有问号

@RequestMapping(path = "/register", method = RequestMethod.GET) 
    public String userActivation(@RequestParam("token") String token, @RequestParam("code") String code, final Map<String, Object> model) { 
    ... 
} 

所以我期待一个token和URL中的code

我现在面临的问题是,重定向到我的网页服务省略了问号,这样的:

http://myapp/register/&token=sdgddfs&code=fdasgas 

Spring的不匹配我的终点。

有什么办法可以解决这个问题吗?

+0

的注释,这是什么服务,真实重定向到你的页面你可以重新写你的方法?似乎问题在那里tbh – Plog

+0

不幸的是,我没有办法改变该服务的重定向网址。业主坚持要求是合法的。 – algiogia

回答

0

使用@PathVariable代替@RequestParam 的所以你必须像http://myapp/register/sdgddfs/fdasgas的URL,以及方法

@RequestMapping(path = "/register/{token}/{code}") 
public String userActivation(@PathVariable("token") String token, @PathVariable("code") String code) { ... } 
+0

这不适用于当前的重定向网址,因为标记后面没有'/'。我会得到一个包含“&token = ...&code = ...”的变量,我必须解析它 – algiogia