繁体   English   中英

如何在Spring MVC中处理URL和@RequestMapping

[英]How to handle URL and @RequestMapping in Spring MVC

我对处理@RequestMapping的最佳方法有疑问。

例如:

使用这个网址http://localhost:8080/SpringExample/admin/personaListForm/1我到达了一个表单,该表单由此@RequestMapping控制: @RequestMapping("/admin/personaListForm/{tipoPersona}")
如您所见,“ 1”是一个变量。

这是我的表单: <form:form action="personaListFormSent">

如您所见,如果我提交表单,我将被发送到该URL http://localhost:8080/SpringExample/admin/personaListForm/personaListFormSent (因为“ / 1”)。 问题是我不想去那里,我想去http://localhost:8080/SpringExample/admin/personaListFormSent

我可以通过<form:form action="../personaListFormSent">这样的形式来解决编辑表单的问题,但这似乎并不是解决此问题的专业方法,因为如果明天我需要添加更多变量,在表单标签中添加更多的“ ../”。

谢谢

您可以使用${pageContext.request.contextPath}/personaListFormSent

<form:form action="${pageContext.request.contextPath}/personaListFormSent">

因此,发布表单时,您将转到http:// localhost:8080 / SpringExample / personaListFormSent

将它们发送到action =“ / personaListFormSent”。 “ /”是您应用程序的根目录,因此无关紧要的是上下文路径。

问候,

乔治

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM