如何在 spring mvc 中引用另一个映射控制器?

发布于 2024-12-08 20:42:25 字数 499 浏览 0 评论 0原文

我有两个带有 @controller 注释的文件,

第一个包含 @RequestMapping("students") 注释和映射方法,如 @RequestMapping("Add Student", method=RequestMethod.post),

另一个包含 @RequestMapping("teachers") 注释和映射@RequestMapping("Add Teacher", method=RequestMethod.post) 等方法

映射方法“Add Teacher”返回“addTeacher”,这是一个 .jsp 文件。

在 addTeacher.jsp 中,我有以下链接:添加教师 但它不起作用,因为它转到 localhost:8080/SchoolProject/students/Add Teacher/ 我想转到 localhost:8080/SchoolProject/teachers/Add Teacher/

如何重写该 .jsp 文件中的链接以转到教师方法?

I have two files with @controller annotation

the first contains @RequestMapping("students") annotation and mapped methods like @RequestMapping("Add Student", method=RequestMethod.post)

the other one @RequestMapping("teachers") annotation and mapped methods like @RequestMapping("Add Teacher", method=RequestMethod.post)

The mapped method "Add Teacher" returns "addTeacher" which is a .jsp file.

In addTeacher.jsp I have this link: Add Teacher
but it doesn't work because it goes to localhost:8080/SchoolProject/students/Add Teacher/
I want to go to localhost:8080/SchoolProject/teachers/Add Teacher/

How can i rewrite the link from that .jsp file to go to teachers method ?

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

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

发布评论

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

评论(1

血之狂魔 2024-12-15 20:42:25

我不能 100% 确定我完全理解你的问题。但是您可能可以使用 spring 标签库(具体来说: http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/spring.tld.html#spring.tld.url)

像这样的东西应该有效:

<spring:url value="/teachers/Add Teacher/"/>

I'm not 100% sure I am fully understanding your issue. But you can probably use the spring tag library (specifically: http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/spring.tld.html#spring.tld.url)

Something like this should work:

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