如何在 Java 上为网站创建漂亮的 URL(永久链接)?
我想为我的 Java 网络项目制作漂亮的 URL。
例如,我有如下 URL:
- www.mysite.com/web/controller?command=showNews&newsId=1
- www.mysite.com/web/controller?command=showNews&newsId=2
- www.mysite.com/web /controller?command=showNews&newsId=3
或
- www.mysite.com/web/user.do?action=start
- www.mysite.com/web/user.do?action=showCategory&category=videoGames§ion=AboutGames
但它不是那么漂亮和用户友好......
我想建立这样的链接:
- www.mysite.com/web /2011/10/04/史蒂夫-乔布斯-iPhone-5/
- www.mysite.com/web/2011/10/23/Facebook-Timeline/
- www.mysite.com/web/2012/05/25/Vladimir-Putin-Russian-President/
你能帮我吗?我怎样才能得到它?
如果有帮助的话,可以使用任何 Java 框架或库。
谢谢你!
更新:我找到了解决方案 - Spring MVC 与 Controller
的 @RequestMapping("/Putin")
注释为例。
I would like to make pretty URLs for my web projects on Java.
For example, I have URLs like these:
- www.mysite.com/web/controller?command=showNews&newsId=1
- www.mysite.com/web/controller?command=showNews&newsId=2
- www.mysite.com/web/controller?command=showNews&newsId=3
or
- www.mysite.com/web/user.do?action=start
- www.mysite.com/web/user.do?action=showCategory&category=videoGames§ion=AboutGames
But it isn't so pretty and userfriendly...
I want to make links like these:
- www.mysite.com/web/2011/10/04/Steve-Jobs-iPhone-5/
- www.mysite.com/web/2011/10/23/Facebook-Timeline/
- www.mysite.com/web/2012/05/25/Vladimir-Putin-Russian-President/
Сan you help me with this? How can I get it?
It's possible to use any Java frameworks or libs if it's help.
Thank you!
Update: I found solution - Spring MVC with Controller
's @RequestMapping("/Putin")
annotation for example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上下文框架 可以让您做到这一点。例如,您给出的示例可以在视图中像这样映射:
Context Framework allows you to do just that. For instance the examples you gave could be mapped like this in a view: