gpt4 book ai didi

java - 如何将子文件夹请求转换为参数

转载 作者:行者123 更新时间:2023-12-02 00:47:28 25 4
gpt4 key购买 nike

我使用的是 Java 服务器,我需要请求中的子文件夹来充当参数。

示例:

myhost/p/a/1

我需要服务器像这样“理解”它:

myhost/p?a=1

我怎样才能做到这一点?

谢谢,科比

最佳答案

1:spring 3 mvc @RequestMapping标签可以从uri中提取路径值

 @RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)  
public String findOwner(@PathVariable String ownerId, Model model) {
Owner owner = ownerService.findOwner(ownerId);
model.addAttribute("owner", owner);
return "displayOwner";
}

2:使用UrlRewiter:http://www.tuckey.org/urlrewrite/ 。这可以使用正则表达式提取路径参数。

<rule>  
<from>^/image/([A-Za-z0-9-]+).html\??(.*)?$</from>
<to>/image.html?imagecode=$1&amp;$2</to>
</rule>

关于java - 如何将子文件夹请求转换为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4544951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com