如何在Spring-mvc中使用html链接调用控制器? [英] How to invoke a controller using a html link in Spring-mvc?
本文介绍了如何在Spring-mvc中使用html链接调用控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为reports.jsp的jsp页面,我在视图中显示了链接,供用户点击。
如何通过单击将传递参数的链接来调用Spring控制器方法。
I have a jsp page called reports.jsp and I have displayed the links in the view for a user to click. How can I invoke Spring controller method by clicking on the link that will pass an argument.
推荐答案
你必须使用 @PathVariable
来执行此操作。示例:
You have to use @PathVariable
in order to do this. Example:
Jsp:
<a href="<c:url value="/test/${object.argument}" />" >hello</a>
控制器:
@RequestMapping(value = "/test/{argument}", method = RequestMethod.GET)
public String Controller(@PathVariable("argument") String argument) {
...
}
这篇关于如何在Spring-mvc中使用html链接调用控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文