作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我使用的是 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/
我是一名优秀的程序员,十分优秀!