替换在 web.xml 中春季MVC

发布于 2025-01-03 19:23:21 字数 205 浏览 5 评论 0原文

因为我的 URL 非常复杂,并且斜杠之间的每个部分都取决于我的数据库的内容,所以我认为这对我来说还不够。我想我需要编写一些 URL 解析器,它会遍历斜杠之间的 url 部分并调用某种处理程序。

有没有办法编写这样的 URL 解析器,它会获取字符串并返回一个代表当前请求的对象,该对象将替换 ?我只找到了仅使用 web.xml 定义的 url 路由的简单教程。

谢谢

Because my URLs are really complex and each of the parts between the slashes depends on the content of my database, I suppose the is not sufficient for me. I suppose I need to write some URL parser, which goes through the url parts between the slash and calls some kind of handler.

Is there a way how to write such URL parser, which would get string and return an object, representing the current request, that would replace the ? I only managed to find simple tutorials which use only the url-routing defined by web.xml.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烈酒灼喉 2025-01-10 19:23:21

Spring 非常灵活,因此您可以自定义 URL 解析。看看本教程 http ://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch16s11.html,注意DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter。看来你应该研究它们是如何工作的并覆盖一些功能。

但在开始之前,请三思。您真的需要这个并且 @RequestMapping 不能满足您吗?实际上,您可以在 URL 模式定义中使用路径变量 {myvar} 。变量可以是不同类型,包括枚举。我用过这个,发现非常方便。例如,您可以创建enum MyType ONE, TWO;在枚举级别定义抽象方法并为每个元素覆盖它。然后,您可以在请求映射中使用 MyType 类型的路径变量,并直接从标有 @RequesteMapping 注解的方法中调用此方法。

Spring is extremely flexible, so you can customize URL parsing. Take a look on this tutorial http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch16s11.html, pay attention on DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter. It seems you should study how do they work and override some of the functionality.

But before you are starting, think again. Do you really need this and @RequestMapping does not satisfy you? Really, you can use path variable {myvar} into the URL pattern definition. The variables may be of different types including enums. I used this and found very convenient. You can for example create enum MyType ONE, TWO; define abstract method on enum level and override it for each element. Then you can use path variable of type MyType into the request mapping and call this method directly from the method marked with @RequesteMapping annotation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文