如何在Spring-mvc中使用html链接调用控制器?

Aki*_*008 1 javascript java jsp spring-mvc

我有一个名为reports.jsp的jsp页面,我在视图中显示了链接,供用户点击.如何通过单击将传递参数的链接来调用Spring控制器方法.

Geo*_*Ant 7

您必须使用@PathVariable才能执行此操作.例:

JSP:

<a href="<c:url value="/test/${object.argument}" />" >hello</a>
Run Code Online (Sandbox Code Playgroud)

控制器:

@RequestMapping(value = "/test/{argument}", method = RequestMethod.GET)
    public String Controller(@PathVariable("argument") String argument) {
       ...
    }
Run Code Online (Sandbox Code Playgroud)