如何在Spring-mvc中使用html链接调用控制器?
我有一个名为reports.jsp的jsp页面,我在视图中显示了链接,供用户点击。 如何通过单击将传递参数的链接来调用Spring控制器方法。
您必须使用@PathVariable
才能执行此操作。 例:
JSP:
" >hello
控制器:
@RequestMapping(value = "/test/{argument}", method = RequestMethod.GET) public String Controller(@PathVariable("argument") String argument) { ... }
我通过创建链接解决了答案:
hello
控制器:
@RequestMapping(value = "/test", method = RequestMethod.GET, params = {"argName"}) public String Controller(@RequestParam(value="argName", required = true, defaultValue = null) String argName) { ... //Now do exciting things with variable argName }