首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpringMVC url路径模式替换

SpringMVC url路径模式替换
EN

Stack Overflow用户
提问于 2016-02-22 04:06:50
回答 1查看 1.3K关注 0票数 1

我在SpringMVC中有一个url路径模式,如下所示:

代码语言:javascript
复制
/person/{personId}/address/{addressId}

我有personId =2和addressId =3,我有一个简单的方法来生成

代码语言:javascript
复制
/person/2/address/3 

在SpringMvc中使用实用方法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-22 14:07:06

看看UriTemplate类。您可以从URL构建自己的UriTemplate,然后展开模板变量。

代码语言:javascript
复制
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("booking", "42");
uriVariables.put("hotel", "1");
System.out.println(template.expand(uriVariables));
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35545665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档