问题描述
我想使用Spring MVC @RequestMapping
注释以这种方式将我的控制器附加到请求:
I would like to use Spring MVC @RequestMapping
annotation to attach my controller to requests in such way:
@RequestMapping(method = RequestMethod.GET, value="/prod/{value:.+}/show")
public String getProduct(
@PathVariable("value") String value,
ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
...
}
当请求将是
(..)/prod/foo/show
我的值变量将 foo
当请求将
(..)/prod/foo/bar/show
我的值变量将 foo / bar
etc
my value variable will have foo/bar
etc
有没有办法做到这一点?支持 @RequestMapping
支持通配符?
Is there any way to do that? What @RequestMapping
wildcards are supported?
推荐答案
如果我理解你的话您需要从视图传递给控制器一个String,例如,包含一些野性字符。
当您在控制器上收到此字符串时,您将在野性字符之前找到值。
If I understood you well that you need to pass from your view to the controller a String, for example, that contains some wild character.When you receive this String on the controller you will just find the values before your wild character.
这种行为是有道理的,因为您无法添加。 或/,#进入网址。
如果您使用的是freemarker,可以使用?url:http://freemarker.sourceforge.net/docs/ref_builtins_string.html#ref_builtin_url
This behavior makes sense as you can't add "." or "/" ,"#" into url .If you are using a freemarker , you can do this by using ?url :http://freemarker.sourceforge.net/docs/ref_builtins_string.html#ref_builtin_url
此外,您可以在此处看到。,点:
没有ASCII十六进制等效代码,因此您需要将其从代码更改为类似#的内容从控制器的视图。
Additionally, the ".",the dot as you can see here : http://www.december.com/html/spec/esccodes.htmldoesn't have ASCII hexadecimal equivalent code so you will need to alter it from the code to be something like "#" to be passed from the view to the controller.
这篇关于@RequestMapping控制器和动态URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!