Spring MVC @PathVariable 被截断 [英] Spring MVC @PathVariable getting truncated
问题描述
我有一个提供 RESTful 信息访问的控制器:
I have a controller that provides RESTful access to information:
@RequestMapping(method = RequestMethod.GET, value = Routes.BLAH_GET + "/{blahName}")
public ModelAndView getBlah(@PathVariable String blahName, HttpServletRequest request,
HttpServletResponse response) {
我遇到的问题是,如果我使用带有特殊字符的路径变量访问服务器,它会被截断.例如:http://localhost:8080/blah-server/blah/get/blah2010.08.19-02:25:47
The problem I am experiencing is that if I hit the server with a path variable with special characters it gets truncated. For example: http://localhost:8080/blah-server/blah/get/blah2010.08.19-02:25:47
参数 blahName 将为 blah2010.08
The parameter blahName will be blah2010.08
但是,对 request.getRequestURI() 的调用包含传入的所有信息.
However, the call to request.getRequestURI() contains all the information passed in.
知道如何防止 Spring 截断 @PathVariable 吗?
Any idea how to prevent Spring from truncating the @PathVariable?
推荐答案
尝试 @RequestMapping
参数的正则表达式:
Try a regular expression for the @RequestMapping
argument:
RequestMapping(method = RequestMethod.GET, value = Routes.BLAH_GET + "/{blahName:.+}")
这篇关于Spring MVC @PathVariable 被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!