Spring 3.0 多个@PathVariable的问题
在我的应用程序中,我必须比较控制器中的 3 个产品,
@RequestMapping(value = "/products/{proId1}Vs{proId2}Vs{proId3}", method = RequestMethod.GET)
public ModelAndView compareThreeProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2, @PathVariable("proId3") int id3)
{
//someLogic
当点击我的 url(http://something/products/12Vs13Vs14) 时,
我映射了请求,我收到 http 400 错误,
我也尝试了 2 个 @pathVariable,如下
@RequestMapping(value = "/products/{proId1}Vs{proId2}", method = RequestMethod.GET)
public ModelAndView compareTwoProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2)
所示工作正常,但为什么我面临 3 个变量的问题,而且服务器日志中也没有错误,那么如何找到错误所在。
有什么解决办法吗??
In my application I have to compare 3 products for that in my controller I mapped request as
@RequestMapping(value = "/products/{proId1}Vs{proId2}Vs{proId3}", method = RequestMethod.GET)
public ModelAndView compareThreeProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2, @PathVariable("proId3") int id3)
{
//someLogic
when hit my url(http://something/products/12Vs13Vs14)
I'm getting http 400 error
I also tried for 2 @pathVariable like
@RequestMapping(value = "/products/{proId1}Vs{proId2}", method = RequestMethod.GET)
public ModelAndView compareTwoProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2)
this is working fine but why i'm facing problem with 3 variables and also there are no errors in server log then how to find what's the bug.
any solution??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何显式指定您希望每个路径变量匹配的正则表达式,如所述 这里?
@RequestMapping(value = "/products/{proId1:\d+}Vs{proId2:\d+}Vs{proId3:\d+}", method = RequestMethod.GET)
How about explicitly specifying the regex you want each path variable to match, as described here?
@RequestMapping(value = "/products/{proId1:\d+}Vs{proId2:\d+}Vs{proId3:\d+}", method = RequestMethod.GET)
您可以尝试将所有内容集中到一个路径变量中,然后手动解析它:
不过,这更多的是一种解决方法,而不是解决方案。如果您想尝试找出到底出了什么问题,您可能需要按照 Bozho 的建议在 Spring 代码中进行调试。
You could try lumping everything into one path variable then parsing it manually:
This is more of a workaround than a solution, though. You might want to debug in the Spring code as Bozho suggested if you want to try to figure out exactly what's going wrong.
/products/{p1}/{p2}/{p3}
或/products/{p1}/vs/{p2}/vs/{p3}
/products/{p1}/{p2}/{p3}
or/products/{p1}/vs/{p2}/vs/{p3}