gpt4 book ai didi

spring - 如何在 Spring 3 中的 Controller 内生成 URI

转载 作者:IT老高 更新时间:2023-10-28 13:57:59 26 4
gpt4 key购买 nike

我使用的是 spring 3.0,我有一个非常简单的问题,但在互联网上没有找到任何答案。我想生成一个路径(URI),就像在我的 JSP 中一样:

<spring:url value="/my/url" />

但在 Controller 内部。使用什么相关服务?谢谢!

编辑:可能与此有关:http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-resourceloader ?没有更好的解决方案吗?

最佳答案

罗森的建议是金子。

还有来自 3.1 的 ServletUriComponentsBuilder 类,它以静态方式从当前请求构建 URL。例如:

ServletUriComponentsBuilder.fromCurrentContextPath().path("/my/additional/path").build().toUriString();

这是最接近 <spring:url> 的东西在 servlet 中。

关于spring - 如何在 Spring 3 中的 Controller 内生成 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8761551/

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