@RequestMapping控制器和动态URL [英] @RequestMapping controllers and dynamic URLs

查看:1142
本文介绍了@RequestMapping控制器和动态URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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

此外,您可以在此处看到。,点: http:// www.december.com/html/spec/esccodes.html
没有ASCII十六进制等效代码,因此您需要将其从代码更改为类似#的内容从控制器的视图。

Additionally, the ".",the dot as you can see here : http://www.december.com/html/spec/esccodes.html doesn'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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆