[英]Spring MVC, Thymleaf on ajax call return new HTML page
I am new to thymeleaf. 我是百里香的新手。 I am planning to implement simple web application with html pages.
我打算用html页面实现简单的Web应用程序。 My landing page controller url is below which returns index.html page
我的目标网页控制器网址在下面,该网址返回index.html页面
@RequestMapping("/index")
public String index() {
return "index";
}
I have a button in index.html page which triggers below controller call and want to return a different onclick.html HTML page 我在index.html页面中有一个按钮,该按钮会在控制器调用下方触发,并想返回另一个onclick.html HTML页面
@RequestMapping("/web/onclick/{onclickvar}")
public String onclick(Model model, @PathVariable("onclickvar") String onclickvar) {
//do something with onclickvar
return "onclick";
}
Can anybody provide sample code please. 任何人都可以提供示例代码。
You can use an anchor link instead of a button to do the same. 您可以使用锚链接而不是按钮来执行相同操作。
<a href="onclick.html" th:href="@{/web/onclick/${someValueForClickvar}">Click here to go to onclick.html</a>
The above link will hit the controller and @PathVariable("onclickvar") String onclickvar
should have the value "someValueForClickvar"
. 上面的链接将命中控制器,并且
@PathVariable("onclickvar") String onclickvar
应该具有值"someValueForClickvar"
。
Note : note that here /web/onclick/${someValueForClickvar}
is the value which you want to pass as a path variable so change the variable name accordigly. 注意:请注意,这里
/web/onclick/${someValueForClickvar}
是您要作为路径变量传递的值,因此请按需更改变量名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.