简体   繁体   English

如何在Spring MVC中引用另一个映射的控制器?

[英]how can I refer to another mapped controller in spring mvc?

I have two files with @controller annotation 我有两个带有@controller批注的文件

the first contains @RequestMapping("students") annotation and mapped methods like @RequestMapping("Add Student", method=RequestMethod.post) 第一个包含@RequestMapping(“ students”)批注和映射的方法,例如@RequestMapping(“ Add Student”,method = RequestMethod.post)

the other one @RequestMapping("teachers") annotation and mapped methods like @RequestMapping("Add Teacher", method=RequestMethod.post) 另一个@RequestMapping(“ teachers”)批注和映射的方法,例如@RequestMapping(“ Add Teacher”,method = RequestMethod.post)

The mapped method "Add Teacher" returns "addTeacher" which is a .jsp file. 映射的方法“添加教师”返回.jsp文件“ addTeacher”。

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/ 在addTeacher.jsp中,我具有以下链接:添加教师,但由于它转到localhost:8080 / SchoolProject / students / Add Teacher /而无法正常工作,我想转到localhost:8080 / SchoolProject / teachers /添加老师/

How can i rewrite the link from that .jsp file to go to teachers method ? 我该如何重写该.jsp文件中的链接以转到教师方法?

I'm not 100% sure I am fully understanding your issue. 我不确定100%是否完全了解您的问题。 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 ) 但是您可能可以使用spring标记库(特别是: http : //static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/spring.tld.html#spring.tld。网址

Something like this should work: 这样的事情应该起作用:

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

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

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